Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gateway): fix zlib data error #1364

Merged
merged 1 commit into from
Apr 19, 2022
Merged

fix(gateway): fix zlib data error #1364

merged 1 commit into from
Apr 19, 2022

Conversation

davidffa
Copy link
Contributor

That error was happening because the new zlib context was trying to decompress packets from the old websocket connection, on reconnects.

Debug logs:

1650119933984 /gateway 200: 86ms (8ms avg) | 1/1 left | Reset 1650119933984 (0ms left)
Initializing zlib-sync-based compression
Shard ID 0 connected.
{"op":2,"d":{"v":9,"compress":true,"large_threshold":250,"intents":32767,"properties":{"os":"linux","browser":"Eris","device":"Eris"},"presence":{"activities":null,"afk":false,"since":null,"status":"offline"}}} 0
Ready!
Disconnected // client.on('disconnect')
Immediately reconnecting for potential resume | Attempt 0 0
Initializing zlib-sync-based compression
Shard ID 0 connected. // client.on('connect')
{"op":6,"d":{"session_id":"ed34c5e8998ebd5739a8b1e0596de2e4","seq":229}} 0
{"op":1,"d":236} 0
Ready!
Disconnected // client.on('disconnect')
Immediately reconnecting for potential resume | Attempt 0 0
Initializing zlib-sync-based compression // <----------------------- *
Error: zlib error -3: data error
    at Shard._onWSMessage (/home/david/Desktop/zlibtest/node_modules/eris/lib/gateway/Shard.js:2431:44)
    at WebSocket.emit (node:events:526:28)
    at Receiver.receiverOnMessage (/home/david/Desktop/zlibtest/node_modules/ws/lib/websocket.js:1137:20)
    (...)
Shard ID 0 connected. // client.on('connect') <--------------------- *
Error: zlib error -3: data error
    at Shard._onWSMessage (/home/david/Desktop/zlibtest/node_modules/eris/lib/gateway/Shard.js:2431:44)
    at WebSocket.emit (node:events:526:28)
    at Receiver.receiverOnMessage (/home/david/Desktop/zlibtest/node_modules/ws/lib/websocket.js:1137:20)
    (...)

* As you can see from the debug logs above, the new zlib inflater tried to decompress a payload from the old websocket connection, as the client#connect event was only fired after the zlib error. So the fix is just to remove the old websocket message listener on disconnect method.

P.S.: This issue happens more often on large bots, due to high amount of incoming gateway packets. I tested on my main bot (116 guilds) and it happens, but not on my testing bot (1 guild).

Closes #1144

@abalabahaha abalabahaha merged commit a9b8ad4 into abalabahaha:dev Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zlib error
3 participants