go-ircevent icon indicating copy to clipboard operation
go-ircevent copied to clipboard

deadlock when writeLoop exits with an error

Open slingamn opened this issue 4 years ago • 1 comments

I'm using 8e7ce4b5a1eb84ddfdc8cd31cf0ee87edb4133a0 with some debugging printlns added, so the line numbers are slightly off (I'll provide links to the deadlocking calls as they appear in master):

SIGQUIT: quit
PC=0x46ede1 m=0 sigcode=0

goroutine 45 [semacquire, 24 minutes]:
sync.runtime_Semacquire(0xc0003e6010)
        /usr/local/go/src/runtime/sema.go:56 +0x45
sync.(*WaitGroup).Wait(0xc0003e6008)
        /usr/local/go/src/sync/waitgroup.go:130 +0x65
github.com/thoj/go-ircevent.(*Connection).Loop(0xc0003e6000)
        /redacted/vendor/github.com/thoj/go-ircevent/irc.go:245 +0x268
c2/cmd.(*Consumer).Client(0xc0003820f0, 0xc00009c500)
        /redacted/cmd/consumer.go:315 +0x419
created by c2/cmd.(*Consumer).Run
        /redacted/cmd/consumer.go:109 +0xe5

goroutine 107483 [select, 24 minutes]:
github.com/thoj/go-ircevent.(*Connection).RunCallbacks(0xc0003e6000, 0xc0002c0820)
        /redacted/vendor/github.com/thoj/go-ircevent/irc_callback.go:178 +0x565
github.com/thoj/go-ircevent.(*Connection).readLoop(0xc0003e6000)
        /redacted/vendor/github.com/thoj/go-ircevent/irc.go:88 +0x515
created by github.com/thoj/go-ircevent.(*Connection).Connect
        /redacted/vendor/github.com/thoj/go-ircevent/irc.go:487 +0x45e

goroutine 107785 [chan send, 24 minutes]:
github.com/thoj/go-ircevent.(*Connection).SendRaw(...)
        /redacted/vendor/github.com/thoj/go-ircevent/irc.go:346
c2/cmd.(*Consumer).ParseIRCMessage(0xc0003820f0, 0xc0002c0820)
        /redacted/cmd/consumer.go:665 +0x89e
c2/cmd.(*Consumer).Client.func3(0xc0002c0820)
        /redacted/cmd/consumer.go:291 +0x3b
github.com/thoj/go-ircevent.(*Connection).RunCallbacks.func1(0xc0003e6000, 0x0, 0xc0002c54a0, 0xc0003a6d80, 0xc0002c0820)
        /redacted/vendor/github.com/thoj/go-ircevent/irc_callback.go:164 +0x6d
created by github.com/thoj/go-ircevent.(*Connection).RunCallbacks
        /redacted/vendor/github.com/thoj/go-ircevent/irc_callback.go:162 +0x45e

Here are the deadlocking calls in master:

https://github.com/thoj/go-ircevent/blob/8e7ce4b5a1eb84ddfdc8cd31cf0ee87edb4133a0/irc.go#L242

https://github.com/thoj/go-ircevent/blob/8e7ce4b5a1eb84ddfdc8cd31cf0ee87edb4133a0/irc_callback.go#L178

https://github.com/thoj/go-ircevent/blob/8e7ce4b5a1eb84ddfdc8cd31cf0ee87edb4133a0/irc.go#L343

From my debugging prints, it appears that writeLoop is exiting with an error here:

https://github.com/thoj/go-ircevent/blob/8e7ce4b5a1eb84ddfdc8cd31cf0ee87edb4133a0/irc.go#L189

and then there's no consumer for attempts to send to (*Connection).pwrite, which blocks our callback from executing, which in turn blocks readLoop from completing.

Thanks for your time!

slingamn avatar Feb 12 '21 00:02 slingamn

Here's a somewhat artificial, but illustrative, test case that reproduces reliably on my system against master:

https://gist.github.com/slingamn/ecafe727b0e2d35f0a04a627436c68ac

slingamn avatar Feb 21 '21 04:02 slingamn