You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bugfix(client): panic: send on closed channel (#179)
* bugfix(client): panic: send on closed channel
Fix:
panic: send on closed channel
goroutine 751872 [running]:
github.com/andreykaipov/goobs.(*Client).writeEvent(...)
/home/xaionaro/.gvm/pkgsets/go1.22.1/global/pkg/mod/github.com/andreykaipov/goobs@v1.4.1/client.go:363
github.com/andreykaipov/goobs.(*Client).handleOpcodes(0xc0020c81a0, 0xc0013846c0)
/home/xaionaro/.gvm/pkgsets/go1.22.1/global/pkg/mod/github.com/andreykaipov/goobs@v1.4.1/client.go:338 +0x5a5
created by github.com/andreykaipov/goobs.(*Client).connect in goroutine 751658
/home/xaionaro/.gvm/pkgsets/go1.22.1/global/pkg/mod/github.com/andreykaipov/goobs@v1.4.1/client.go:200
Essentially by design we should close a channel only after we finished
all possible writing to it. Thus moving the close statement of channel
IncomingResponses to be called right after the writer to the channel is
finished.
* bugfix: Possible race condition in the disconnection procedure
There were three problems:
1. Instead of closing c.Disconnect we were writing a single event there.
Thus if somebody will try to read from the channel the second time,
they'll get blocked, and thus SendRequest will go into the `default`
section of the `select`, which is potentially a panic if `c.Opcodes`
is already closed.
2. The `close` statements in `markDisconnect` are executed without
locking c.client.mutex. As a result there is a possible race
condition that for example c.IncomingEvents is closed,
but c.client.Disconnected is not (which may lead to a panic).
3. The place of the closure of c.client.IncomingResponses is
confusing after 0442e5b.
The problems are now fixed:
1. Now we just close `c.Disconnect` instead of writing an event into it.
2. Now the `close` statements are made atomic via c.client.mutex.
3. Now we have a comment explaining the closure of c.client.IncomingResponses
0 commit comments