Skip to content

Commit

Permalink
bugfix(client): panic: send on closed channel
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xaionaro committed Oct 25, 2024
1 parent bd2c39d commit 0442e5b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ func (c *Client) markDisconnected() {
c.client.Log.Printf("[TRACE] Closing internal channels")
close(c.IncomingEvents)
close(c.client.Opcodes)
close(c.client.IncomingResponses)
close(c.client.Disconnected)
})
}
Expand Down Expand Up @@ -210,7 +209,10 @@ func (c *Client) connect() (err error) {
authComplete := make(chan error)

go c.handleRawServerMessages(authComplete)
go c.handleOpcodes(authComplete)
go func() {
c.handleOpcodes(authComplete)
close(c.client.IncomingResponses)
}()

timer := time.NewTimer(c.client.ResponseTimeout * time.Millisecond)
defer timer.Stop()
Expand Down

0 comments on commit 0442e5b

Please sign in to comment.