Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not close any channels to avoid racy "send on closed channel" panics #16

Closed
wants to merge 1 commit into from

Conversation

flyingmutant
Copy link
Contributor

Example panic, happened after the eventsource was closed:

panic: runtime error: send on closed channel

goroutine 147858 [running]:
runtime.panic(0x465000, 0x77641e)
    /usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/panic.c:279 +0xf5
github.com/sporttech/eventsource.func·001()
    /Users/mrbrbr/dev/go/src/github.com/sporttech/eventsource/consumer.go:73 +0x384

There is no need to close any channels — it does not impact the GC, but
is only a signal to receivers that no data will be following (see
here).

As nothing in this package listens to close() of any channel, simply
removing all close() calls both simplifies the code and avoids
unexpected panic()s.

Example panic, happened after the eventsource was closed:

```
panic: runtime error: send on closed channel

goroutine 147858 [running]:
runtime.panic(0x465000, 0x77641e)
	/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/panic.c:279 +0xf5
github.com/sporttech/eventsource.func·001()
	/Users/mrbrbr/dev/go/src/github.com/sporttech/eventsource/consumer.go:73 +0x384
```

There is no need to close any channels — it does not impact the GC, but
is only a signal to receivers that no data will be following (see
[here](https://groups.google.com/forum/#!msg/golang-nuts/pZwdYRGxCIk/qpbHxRRPJdUJ)).

As nothing in this package listens to `close()` of any channel, simply
removing all `close()` calls both simplifies the code and avoids
unexpected `panic()`s.
@antage
Copy link
Owner

antage commented Sep 13, 2014

This problem is more complex it seems. Removing closes hides leaking goroutines but doesn't solve the problem. I'll think how to fix Close function to avoid panics and sending to closed channels.

I have created issue #17. We can discuss there.

@antage antage closed this Sep 13, 2014
@flyingmutant
Copy link
Contributor Author

Oh, sorry — I somehow missed that newConsumer() starts a goroutine which does listen to closes of .in channel.

If we do close those in .Close() everything looks fine to me. What do you thing?

@antage
Copy link
Owner

antage commented Sep 13, 2014

Goroutine that started in newConsumer may send in staled closed channel (as your example).

@flyingmutant
Copy link
Contributor Author

I was talking about doing this: cc08403

@flyingmutant flyingmutant deleted the noclose branch September 13, 2014 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants