velour / chat

An easy-to-use client for Slack, Telegram, IRC, or all at once!
7 stars 0 forks source link

Crash on bad Slack message #71

Closed chrissexton closed 7 years ago

chrissexton commented 7 years ago

We received this crash:

2017/01/10 13:43:33 Bridge closed with error: failed to receive from velour on hashvelour.slack.com: EOF
panic: json: cannot unmarshal object into Go value of type string

goroutine 1 [running]:
panic(0x676cc0, 0xc4203576b0)
        /home/cws/go/src/runtime/panic.go:500 +0x1a1
main.main.func3(0xc4200b6960, 0x813400, 0xc420010380)
        /home/cws/src/github.com/velour/chat/bridge/main.go:100 +0x7e
main.main()
        /home/cws/src/github.com/velour/chat/bridge/main.go:162 +0x1197
eaburns commented 7 years ago

The error is 'EOF' from Slack. Forever ago with github.com/velour/relay, I was seeing periodic disconnects from Slack. We never solved it and I just ended up running it in a restart loop.

We should solve it now.

eaburns commented 7 years ago

On the other hand, the error could be something totally different, and the EOF could be a red herring. We cancel all Channels on the bridge when something fails. When we close the receivers, Receive will send EOF. Maybe we are reporting that EOF instead of the actual error.

eaburns commented 7 years ago

Ah, but the serialization error is coming from the Slack close call. That's definitely the cause.

eaburns commented 7 years ago

Let's add better logging of json errors. We should capture the message data in a bytes.Buffer, decode it from there, and on error print the data and error offset.

chrissexton commented 7 years ago

A very similar error happened again today (I'm assuming it's the same-ish cause) when I edited my Slack profile.

2017/01/11 11:03:08 Bridge closed with error: failed to receive from velour on hashvelour.slack.com: EOF
panic: json: cannot unmarshal object into Go value of type chat.UserID

goroutine 1 [running]:
panic(0x676cc0, 0xc4203efd40)
        /home/cws/go/src/runtime/panic.go:500 +0x1a1
main.main.func3(0xc4200b6960, 0x813400, 0xc420010380)
        /home/cws/src/github.com/velour/chat/bridge/main.go:100 +0x7e
main.main()
        /home/cws/src/github.com/velour/chat/bridge/main.go:162 +0x1197
2017/01/11 11:03:14 Bridge is up and running.
2017/01/11 11:03:14 Connecting:
2017/01/11 11:03:14      #velour on IRC (irc.freenode.net:6697)
2017/01/11 11:03:14      #velour on Telegram
2017/01/11 11:03:14      velour on hashvelour.slack.com
Message{
        ID: "1484150512.017484"
        From: User{
                ID: "U0RLUDELD"
                Nick: "flyngpngn"
                FullName: "The Hammer"
                DisplayName: "flyngpngn"
                PhotoURL: "https://secure.gravatar.com/avatar/ff57b3a83dcae3ee96233e2f47906ef6.jpg?s=192&d=https%!A(MISSING)%!F(MISSI
NG)%!F(MISSING)a.slack-edge.com%!F(MISSING)7fa9%!F(MISSING)img%!F(MISSING)avatars%!F(MISSING)ava_0015-192.png"
        }
        Text: "I think I know what that error is about"
}
2017/01/11 11:03:57 Bridge closed with error: failed to receive from velour on hashvelour.slack.com: EOF
panic: json: cannot unmarshal object into Go value of type chat.UserID

goroutine 1 [running]:
panic(0x676cc0, 0xc420390450)
        /home/cws/go/src/runtime/panic.go:500 +0x1a1
main.main.func3(0xc4200b6960, 0x813400, 0xc420010380)
        /home/cws/src/github.com/velour/chat/bridge/main.go:100 +0x7e
main.main()
        /home/cws/src/github.com/velour/chat/bridge/main.go:162 +0x1197
eaburns commented 7 years ago

good find!

eaburns commented 7 years ago

Actually, these may be separate issues. One is trying to unmarshall an object into a string, and the other into a chat.UserID.

eaburns commented 7 years ago

Basically the problem is that each event type returned by the RTM API can have a different return. We always assume that it will be structured like Update; that assumption is wrong.

In the case of "type":"user_change", for example, the "user" field is an object; Update assumes that it's as string.