Skip to content

Goroutine leaks? #6

@technosophos

Description

@technosophos

The documentation suggests doing this:

go pubInstance.Publish(<pubnub channel>, <message to publish>, callbackChannel, errorChannel)
go ParseResponse(callbackChannel)
go ParseErrorResponse(errorChannel) 

It appears that Publish() will only send messages on one of the two channels. And (like a good Go receiver) never closes the channels that it receives.

Won't this lead to leaking at least one goroutine for every single Publish?

See, at least one of those two goroutines will block on <-myChannel, which means that goroutine will never be freed.

Wouldn't it make more sense to use a select{} on those two channels and react to whichever one returns first? And probably having a time.Timer to timeout long requests would be a good idea, too, right?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions