42wim / matterircd

Connect to your mattermost or slack using your IRC-client of choice.
MIT License
294 stars 60 forks source link

Slack: runtime error: invalid memory address or nil pointer dereference #455

Closed chex3 closed 2 years ago

chex3 commented 2 years ago

I just setup matterircd to connect to several Slacks I want to be connected to. One of them is small ( less-than 150 accounts ) while the others all have 1000-3000 account users, which has caused issues for other Slack gateways i've tried to use in the past.

I connect to the first Slack fine, but as soon as I connect to the 2nd one, I get a crash of the server.

I am attaching the logfile of the server session here. Also, I am connecting to the spaces with:

/m slack login

Thank you ! matterircd.log

Zauberfisch commented 2 years ago

I don't really care about slack, so I never looked into it, and when it crashes systemd restarts it anyway. But my logs seem to show the same errors (not or not only at login). The VM it's running on has 5GB ram + 4GB swap free.

Dec 30 16:11:29 mattermost matterircd[4547]: slack-go/slack2021/12/30 16:11:29 websocket_managed_conn.go:343: Sending PING  65
Dec 30 16:11:29 mattermost matterircd[4547]: slack-go/slack2021/12/30 16:11:29 websocket_managed_conn.go:387: Incoming Event: {"type":"pong","timestamp":1640880689,"reply_to":65}
Dec 30 16:11:59 mattermost matterircd[4547]: slack-go/slack2021/12/30 16:11:59 websocket_managed_conn.go:343: Sending PING  66
Dec 30 16:11:59 mattermost matterircd[4547]: slack-go/slack2021/12/30 16:11:59 websocket_managed_conn.go:387: Incoming Event: {"type":"pong","timestamp":1640880719,"reply_to":66}
Dec 30 16:12:29 mattermost matterircd[4547]: slack-go/slack2021/12/30 16:12:29 websocket_managed_conn.go:343: Sending PING  67
Dec 30 16:12:29 mattermost matterircd[4547]: slack-go/slack2021/12/30 16:12:29 websocket_managed_conn.go:387: Incoming Event: {"type":"pong","timestamp":1640880749,"reply_to":67}
Dec 30 16:12:49 mattermost matterircd[4547]: panic: runtime error: invalid memory address or nil pointer dereference
Dec 30 16:12:49 mattermost matterircd[4547]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x83caee]
Dec 30 16:12:49 mattermost matterircd[4547]: goroutine 3165 [running]:
Dec 30 16:12:49 mattermost matterircd[4547]: github.com/matterbridge/matterclient.(*Client).HandleRatelimit(0xc0000224d0, {0x9c6247, 0x1a}, 0xc0000b16c0)
Dec 30 16:12:49 mattermost matterircd[4547]:         /home/fisch/.cache/pikaur/build/matterircd/src/src/github.com/42wim/matterircd/vendor/github.com/matterbridge/matterclient/matterclient.go:717 +0x2e
Dec 30 16:12:49 mattermost matterircd[4547]: github.com/matterbridge/matterclient.(*Client).UpdateChannelsTeam(0xc0005182d0, {0xc0007969c0, 0xc00324cd20})
Dec 30 16:12:49 mattermost matterircd[4547]:         /home/fisch/.cache/pikaur/build/matterircd/src/src/github.com/42wim/matterircd/vendor/github.com/matterbridge/matterclient/channels.go:233 +0x231
Dec 30 16:12:49 mattermost matterircd[4547]: github.com/matterbridge/matterclient.(*Client).UpdateChannels(0xc0005182d0)
Dec 30 16:12:49 mattermost matterircd[4547]:         /home/fisch/.cache/pikaur/build/matterircd/src/src/github.com/42wim/matterircd/vendor/github.com/matterbridge/matterclient/channels.go:250 +0x2e
Dec 30 16:12:49 mattermost matterircd[4547]: github.com/42wim/matterircd/bridge/mattermost6.(*Mattermost).UpdateChannels(0xc0049f0500)
Dec 30 16:12:49 mattermost matterircd[4547]:         /home/fisch/.cache/pikaur/build/matterircd/src/src/github.com/42wim/matterircd/bridge/mattermost6/mattermost.go:239 +0x1c
Dec 30 16:12:49 mattermost matterircd[4547]: created by github.com/42wim/matterircd/bridge/mattermost6.(*Mattermost).checkWsActionMessage
Dec 30 16:12:49 mattermost matterircd[4547]:         /home/fisch/.cache/pikaur/build/matterircd/src/src/github.com/42wim/matterircd/bridge/mattermost6/mattermost.go:166 +0xf5
Dec 30 16:12:49 mattermost systemd[1]: matterircd.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Dec 30 16:12:49 mattermost systemd[1]: matterircd.service: Failed with result 'exit-code'.
Dec 30 16:12:49 mattermost systemd[1]: matterircd.service: Consumed 43.048s CPU time.
Dec 30 16:13:04 mattermost systemd[1]: matterircd.service: Scheduled restart job, restart counter is at 3.
Dec 30 16:13:04 mattermost systemd[1]: Stopped minimal IRC server which integrates with mattermost and slack.
Dec 30 16:13:04 mattermost systemd[1]: matterircd.service: Consumed 43.048s CPU time.
Dec 30 16:13:04 mattermost systemd[1]: Started minimal IRC server which integrates with mattermost and slack.
Dec 30 16:13:04 mattermost matterircd[4592]: time="2021-12-30T16:13:04Z" level=info msg="Running version 0.25.0 " module=matterircd
chex3 commented 2 years ago

Hi, after working with Zauberfisch on IRC, we determined what I was doing to connect multiple slack servers was wrong. I needed to have a separate IRC network for each Slack I wanted to connect to, and re-connect to matterircd as a separate IRC server connection for each Slack.

And this works, I was able to connect to 4 Slacks all at the same time now.

I am removing this issue post, but someone should add this to the doc notes on connecting to Slack servers.

Thank you for the help, Zauberfisch.

Zauberfisch commented 2 years ago

please keep this open, the error still happens according to my logs

Zauberfisch commented 2 years ago

possibly related to https://github.com/42wim/matterircd/issues/428 May I suggest a title change to "slack: runtime error: invalid memory address or nil pointer dereference"

Zauberfisch commented 2 years ago

hmm. looking into it further, our logs actually have a different trace. My error seems to occur for the mattermost bridge, not for slack (but also with lots of users (community.mattermost.com))

chex3 commented 2 years ago

I believe what was happening is when you try to connect to a 2nd slack on the SAME IRC-server/network connection matterircd attempts to log out of the 1st slack, then log into the 2nd (and then crash, for some unknown reason) If you use separate connections per slack authentication, then it is fine. I will leave this open for now just to see how stable matterircd server is over the next few days, if no further issues, then I will close.

42wim commented 2 years ago

@Zauberfisch your issue is completely different, moved to #457 @chex3 seems like an issue in the slack go library it self, it shouldn't crash. I just updated master with latest library, can you check if it crashes there too? But yes, if you connect to another slack on the same connection it will disconnect, you can't have 2 connections to multiple slacks on the same connection (wouldn't be workable .. what to do with name/channel conflicts etc..)

Zauberfisch commented 2 years ago

yep, figured it must be something different only after I had already posted. Thanks for splitting it out of this issue.

chex3 commented 2 years ago

@42wim I was able to get 2 Slacks connected and working on the same connection occasionally, but most of the time, the server just crashes. I was thinking that is how it works, because the libpurple-slack plugin in bitlbee works this way; you just keep adding Slack servers to the same 'session' and it just names the servers slack1, slack2, etc. I can see how channel names could be an issue, not sure how the purple plugin handles that.

In any case, having separate IRC server connection for each slack is slightly challenging for my IRC setup, but its fine, just glad its working. Been connected to 4 slacks now for over a day, no issues at all, server is running great.

I am closing this Issue now.

Thanks again, and regards, Stefan