lrstanley / girc

:bomb: girc is a flexible IRC library for Go :ok_hand:
https://pkg.go.dev/github.com/lrstanley/girc
MIT License
138 stars 13 forks source link

Runtime error when using the client during reconnect #14

Closed fleaz closed 5 years ago

fleaz commented 6 years ago

Hi,

I'm using the girc library in one of my projects and just added some code from the girc examples to reconnecting to the IRC server. This works perfectly fine and when the connection is lost, he reconencts automatically after the given delay. But the problem is, that when a other goroutine tries to call e.g. Cmd.Message() to send something during the time between the connection is lost and girc reconnects, it ends up with a SIGSEGV and crashes. See the attached stacktrace

I'm not sure if this is a library problem of girc or if I should catch this and don't use the client during reconenction.

Please let me know if you need more informations to debug this.

Best regards, Felix

2018/08/15 22:09:11 Connection to irc.hackint.eu:6667 terminated: timed out waiting for a requested PING response
2018/08/15 22:09:11 Reconnecting to irc.hackint.eu:6667 in 30 seconds...

<other gorouting calls Cmd.Message() at this moment>

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7c03ff]

goroutine 18 [running]:
github.com/lrstanley/girc.(*ircConn).rate(0x0, 0x15, 0x0)
    /home/fleaz/workspace/go/src/github.com/lrstanley/girc/conn.go:411 +0x2f
github.com/lrstanley/girc.(*Client).Send(0xc42018e000, 0xc420310770)
    /home/fleaz/workspace/go/src/github.com/lrstanley/girc/conn.go:389 +0x17d
github.com/lrstanley/girc.(*Commands).Message(0xc42017a030, 0xc420024a24, 0x6, 0xc4203331c0, 0x5)
    /home/fleaz/workspace/go/src/github.com/lrstanley/girc/commands.go:108 +0xf5
main.channelReceiver()
    /home/fleaz/workspace/go/src/github.com/f-breidenstein/CptHook/irc.go:106 +0xe8
created by main.ircConnection
    /home/fleaz/workspace/go/src/github.com/f-breidenstein/CptHook/irc.go:87 +0x339
lrstanley commented 5 years ago

I'm sorry for the delay -- I've been quite busy with IRL issues. Generally speaking, I haven't done too much testing in regards to sending things outside of the main callback event loops (e.g. Add(), AddBg()). This is in fact a bug -- not quite sure how I want to solve it yet though.

lrstanley commented 5 years ago

I'm very late to getting this resolved, sorry about that. I see you found a workaround, though let me know if you see any further issues. I was putting off, thinking it was going to be quite a bit of a rewrite to resolve, but looks like it was specifically related to ratelimiting (and thus much easier to fix).