Same symptoms as #2227. Every 2-3 days (I think?) my bot becomes unresponsive.
I added a global error handler last time it happened and this is what it logged:
Error
Unhandled error: read ECONNRESET ErrorEvent {
target:
WebSocket {
_events:
{ message: [Function],
open: [Function],
error: [Function],
close: [Function] },
_eventsCount: 4,
_maxListeners: undefined,
readyState: 2,
protocol: '',
_binaryType: 'nodebuffer',
_finalize: [Function: bound finalize],
_closeFrameReceived: false,
_closeFrameSent: false,
_closeMessage: '',
_closeTimer: null,
_finalized: true,
_closeCode: 1006,
_extensions: {},
_isServer: false,
_receiver:
Receiver {
_binaryType: 'nodebuffer',
_extensions: null,
_maxPayload: 0,
_bufferedBytes: 0,
_buffers: null,
_compressed: false,
_payloadLength: 36,
_fragmented: 0,
_masked: false,
_fin: true,
_mask: null,
_opcode: 1,
_totalPayloadLength: 0,
_messageLength: 0,
_fragments: null,
_cleanupCallback: null,
_isCleaningUp: false,
_hadError: false,
_loop: false,
add: [Function: bound add],
onmessage: null,
onclose: null,
onerror: null,
onping: null,
onpong: null,
_state: 0 },
_sender:
Sender {
_extensions: {},
_socket: [TLSSocket],
_firstFragment: true,
_compress: false,
_bufferedBytes: 0,
_deflating: false,
_queue: [] },
_socket:
TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: 'gateway.discord.gg',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object],
_eventsCount: 4,
connecting: false,
_hadError: false,
_handle: null,
_parent: null,
_host: 'gateway.discord.gg',
_readableState: [ReadableState],
readable: false,
_maxListeners: undefined,
_writableState: [WritableState],
writable: false,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: null,
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: null,
[Symbol(res)]: [TLSWrap],
[Symbol(asyncId)]: 2054144,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBytesRead)]: 17813,
[Symbol(kBytesWritten)]: 9657,
[Symbol(connect-options)]: [Object] },
_error: null,
url: 'wss://gateway.discord.gg/?v=6&encoding=json',
_req: null },
type: 'error',
message: 'read ECONNRESET',
error:
{ Error: read ECONNRESET
at TLSWrap.onread (net.js:656:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' } }
{"target":{"_events":{},"_eventsCount":4,"readyState":2,"protocol":"","_binaryType":"nodebuffer","_closeFrameReceived":false,"_closeFrameSent":false,"_closeMessage":"","_closeTimer":null,"_finalized":true,"_closeCode":1006,"_extensions":{},"_isServer":false,"_receiver":{"_binaryType":"nodebuffer","_extensions":null,"_maxPayload":0,"_bufferedBytes":0,"_buffers":null,"_compressed":false,"_payloadLength":36,"_fragmented":0,"_masked":false,"_fin":true,"_mask":null,"_opcode":1,"_totalPayloadLength":0,"_messageLength":0,"_fragments":null,"_cleanupCallback":null,"_isCleaningUp":false,"_hadError":false,"_loop":false,"onmessage":null,"onclose":null,"onerror":null,"onping":null,"onpong":null,"_state":0},"_sender":{"_extensions":{},"_socket":{"_tlsOptions":{"pipe":false,"secureContext":{"context":{},"singleUse":true},"isServer":false,"requestCert":true,"rejectUnauthorized":true,"session":{"type":"Buffer","data":[... add: [Function: bound add],
onmessage: null,
onclose: null,
onerror: null,
onping: null,
onpong: null,
_state: 0 },
_sender:
Sender {
_extensions: {},
_socket: [TLSSocket],
_firstFragment: true,
_compress: false,
_bufferedBytes: 0,
_deflating: false,
_queue: [] },
_socket:
TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: 'gateway.discord.gg',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object],
_eventsCount: 4,
connecting: false,
_hadError: false,
_handle: null,
_parent: null,
_host: 'gateway.discord.gg',
_readableState: [ReadableState],
readable: false,
_maxListeners: undefined,
_writableState: [WritableState],
writable: false,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: null,
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: null,
[Symbol(res)]: [TLSWrap],
[Symbol(asyncId)]: 2054144,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBytesRead)]: 17813,
[Symbol(kBytesWritten)]: 9657,
[Symbol(connect-options)]: [Object] },
_error: null,
url: 'wss://gateway.discord.gg/?v=6&encoding=json',
_req: null },
type: 'error',
message: 'read ECONNRESET',
error:
{ Error: read ECONNRESET
at TLSWrap.onread (net.js:656:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' } }
{"target":{"_events":{},"_eventsCount":4,"readyState":2,"protocol":"","_binaryType":"nodebuffer","_closeFrameReceived":false,"_closeFrameSent":false,"_closeMessage":"","_closeTimer":null,"_finalized":true,"_closeCode":1006,"_extensions":
{},"_isServer":false,"_receiver":{"_binaryType":"nodebuffer","_extensions":null,"_maxPayload":0,"_bufferedBytes":0,"_buffers":null,"_compressed":false,"_payloadLength":36,"_fragmented":0,"_masked":false,"_fin":true,"_mask":null,"_opcode"
:1,"_totalPayloadLength":0,"_messageLength":0,"_fragments":null,"_cleanupCallback":null,"_isCleaningUp":false,"_hadError":false,"_loop":false,"onmessage":null,"onclose":null,"onerror":null,"onping":null,"onpong":null,"_state":0},"_sender
":{"_extensions":{},"_socket":{"_tlsOptions":{"pipe":false,"secureContext":{"context":{},"singleUse":true},"isServer":false,"requestCert":true,"rejectUnauthorized":true,"session":{"type":"Buffer","data":[...]}},"_secureEstablished":true,"_securePending":false,"_newSessionPending":false,"_controlReleased":true,"_SNICallback":null,"servername":"gateway.discord.gg","alpnProtocol":false,"authorized":true,"authorizationError":null,"encrypted":true,"_events":{"close":[null,null]},"_eventsCount":4,"connecting":false,"_hadError":false,"_handle":null,"_parent":null,"_host":"gateway.discord.gg","_readableState":{"objectMode":false,"highWaterMark":16384,"buffer":{"head":null,"tail":null,"length":0},"length":0,"pipes":null,"pipesCount":0,"flowing":true,"ended":false,"endEmitted":false,"reading":true,"sync":false,"needReadable":true,"emittedReadable":false,"readableListening":false,"resumeScheduled":false,"emitClose":false,"destroyed":true,"defaultEncoding":"utf8","awaitDrain":0,"readingMore":false,"decoder":null,"encoding":null},"readable":false,"_writableState":{"objectMode":false,"highWaterMark":16384,"finalCalled":false,"needDrain":false,"ending":false,"ended":false,"finished":false,"destroyed":true,"decodeStrings":false,"defaultEncoding":"utf8","length":0,"writing":false,"corked":0,"sync":false,"bufferProcessing":false,"writecb":null,"writelen":0,"bufferedRequest":null,"lastBufferedRequest":null,"pendingcb":0,"prefinished":false,"errorEmitted":true,"emitClose":false,"bufferedRequestCount":0,"corkedRequestsFree":{"next":null,"entry":null}},"writable":false,"allowHalfOpen":false,"_sockname":null,"_pendingData":null,"_pendingEncoding":"","_server":null,"ssl":null,"_requestCert":true,"_rejectUnauthorized":true,"parser":null,"_httpMessage":null},"_firstFragment":true,"_compress":false,"_bufferedBytes":0,"_deflating":false,"_queue":[]},"_socket":{"_tlsOptions":{"pipe":false,"secureContext":{"context":{},"singleUse":true},"isServer":false,"requestCert":true,"rejectUnauthorized":true,"session":{"type":"Buffer","data":[...]}},"_secureEstablished":true,"_securePending":false,"_newSessionPending":false,"_controlReleased":true,"_SNICallback":null,"servername":"gateway.discord.gg","alpnProtocol":false,"authorized":true,"authorizationError":null,"encrypted":true,"_events":{"close":[null,null]},"_eventsCount":4,"connecting":false,"_hadError":false,"_handle":null,"_parent":null,"_host":"gateway.discord.gg","_readableState":{"objectMode":false,"highWaterMark":16384,"buffer":{"head":null,"tail":null,"length":0},"length":0,"pipes":null,"pipesCount":0,"flowing":true,"ended":false,"endEmitted":false,"reading":true,"sync":false,"needReadable":true,"emittedReadable":false,"readableListening":false,"resumeScheduled":false,"emitClose":false,"destroyed":true,"defaultEncoding":"utf8","awaitDrain":0,"readingMore":false,"decoder":null,"encoding":null},"readable":false,"_writableState":{"objectMode":false,"highWaterMark":16384,"finalCalled":false,"needDrain":false,"ending":false,"ended":false,"finished":false,"destroyed":true,"decodeStrings":false,"defaultEncoding":"utf8","length":0,"writing":false,"corked":0,"sync":false,"bufferProcessing":false,"writecb":null,"writelen":0,"bufferedRequest":null,"lastBufferedRequest":null,"pendingcb":0,"prefinished":false,"errorEmitted":true,"emitClose":false,"bufferedRequestCount":0,"corkedRequestsFree":{"next":null,"entry":null}},"writable":false,"allowHalfOpen":false,"_sockname":null,"_pendingData":null,"_pendingEncoding":"","_server":null,"ssl":null,"_requestCert":true,"_rejectUnauthorized":true,"parser":null,"_httpMessage":null},"_error":null,"url":"wss://gateway.discord.gg/?v=6&encoding=json","_req":null},"type":"error","message":"read ECONNRESET","error":{"errno":"ECONNRESET","code":"ECONNRESET","syscall":"read"}}
(node:68093) UnhandledPromiseRejectionWarning: Error: Something took too long to do.
at timeout.client.setTimeout (/node_modules/discord.js/src/client/ClientManager.js:40:57)
at Timeout.setTimeout [as _onTimeout] (/node_modules/discord.js/src/client/Client.js:433:7)
at ontimeout (timers.js:427:11)
at tryOnTimeout (timers.js:289:5)
at listOnTimeout (timers.js:252:5)
at Timer.processTimers (timers.js:212:10)
(node:68093) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:68093) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
npm list
+-- @types/[email protected]
+-- UNMET PEER DEPENDENCY bufferutil@^3.0.3
+-- [email protected] invalid
| +-- [email protected] extraneous
| +-- [email protected] extraneous
| +-- [email protected] extraneous
| +-- [email protected] extraneous
| `-- [email protected] extraneous
+-- UNMET PEER DEPENDENCY erlpack@discordapp/erlpack
+-- [email protected]
+-- [email protected]
| +-- [email protected]
| +-- [email protected]
| | +-- [email protected] deduped
| | `-- [email protected]
| +-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| | +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| | `-- [email protected] deduped
| `-- [email protected]
+-- UNMET PEER DEPENDENCY libsodium-wrappers@^0.7.3
+-- UNMET PEER DEPENDENCY node-opus@^0.2.7
+-- UNMET PEER DEPENDENCY opusscript@^0.0.6
+-- UNMET PEER DEPENDENCY sodium@^2.0.3
+-- [email protected]
`-- UNMET PEER DEPENDENCY uws@^9.14.0
npm ERR! peer dep missing: bufferutil@^3.0.3, required by [email protected]
npm ERR! peer dep missing: erlpack@discordapp/erlpack, required by [email protected]
npm ERR! peer dep missing: node-opus@^0.2.7, required by [email protected]
npm ERR! peer dep missing: opusscript@^0.0.6, required by [email protected]
npm ERR! peer dep missing: sodium@^2.0.3, required by [email protected]
npm ERR! peer dep missing: libsodium-wrappers@^0.7.3, required by [email protected]
npm ERR! peer dep missing: uws@^9.14.0, required by [email protected]
npm ERR! invalid: [email protected] /usr/home/rupug/rupug/node_modules/discord.js
npm ERR! extraneous: [email protected] /usr/home/rupug/rupug/node_modules/long
npm ERR! extraneous: [email protected] /usr/home/rupug/rupug/node_modules/prism-media
npm ERR! extraneous: [email protected] /usr/home/rupug/rupug/node_modules/snekfetch
npm ERR! extraneous: [email protected] /usr/home/rupug/rupug/node_modules/tweetnacl
npm ERR! extraneous: [email protected] /usr/home/rupug/rupug/node_modules/ws
$ node -v
v10.5.0
"dependencies": {
"discord.js": "latest",
"getopts": "latest",
"glob": "latest"
},
"devDependencies": {
"@types/node": "latest",
"typescript": "latest"
}
There doesn't seem to be a reconnect method so I'll have to rewrite stuff to work around this and make a new client in the meantime I guess.
ECONNRESET usually means the internet connection dies somewhere along the way, there's nothing much the lib can do about it.
A process manager or client destroy + reconnect is probably the way to go. You can most likely go to the Discord server in order to ask further questions.
You can "handle" WebSocket connection failures via the Client#error event, the client will try to reconnect on its own then and the process won't crash.
Regarding the Something took too long to do error, there isn't much to say without the debug logs. (Client#debug event)
Although that error should only be able to be thrown (or rejected) by the initial login, not after 2-3 days.
Huh, so it's unable to catch ECONNRESET and reconnect on its own? Or it was designed not to? In order to "handle" the client#error event so it will try to reconnect, do I just add an .on('client#error',()=>{}) to the client? None of this seems to be documented.
Right now, I attempt to catch all errors (to figure out what was going on) via process.on("uncaughtException"). When they happen I call destroy on the client and try to make a new one. That's the only way I could think of to "handle" it, as there doesn't seem to be any client methods for reconnecting. However, this doesn't seem to actually work. I need to log in and kill -9 node to get it to go away, then restart it.
I really wasn't expecting to have to deal with this stuff. Is the normal recommendation to just let Node die and restart the process?
Ah, thanks, updated with that and will see what turns up.
Catching the error worked, it no longer stops responding, so I'll close this.
However, I would argue that this should be handled by the library. The way it works seems backwards. I would think it would at least try to reconnect by default, and I would catch the error if I wanted to handle it myself (and not reconnect) or handle it after a few attempts.
I'm also having this problem. Since about 3 months ago the bot on one of my server literally dies after a couple hours with connection reset, if I move all the code to a different server in same data center it works fine.
Just yesterday another of my 3 total servers started that behaviour.
I'll apply this workaround now and I'm confident that it will work fine.
I'm running my bot for about a year now. And the issue only appeared about 3 months ago.
Seems weird that all of a sudden it starts happening, and that multiple people experience the same.
One of my 3 servers is still fine. But it just starts happening someday, and from there on the bot constantly gets connection reset within a few hours from starting up.
I'm thinking its something from discord side killing the connections.
Maybe they are graylisting the IP address and kicking in random intervals?
I still have this issue sporadically, usually when the network hiccups and it can't do a DNS lookup, which is always temporary.
The problem isn't the network, though; network problems are normal. The problem IMO is the library's handling (or lack of handling) of it, and just up and zombifying or crashing, when it should just retry.
FWIW, the process never crashes for me, before or after the workaround, which is part of the problem...it continues to run but just doesn't respond. If it did crash, I could just restart it.
Are you two running the latest master version of discord.js? The reconnect logic has been refactored, and this shouldn't be an issue now... You can log the debug event to see what happens.
FWIW, the process never crashes for me, before or after the workaround, which is part of the problem..
Same.
Are you two running the latest master version of discord.js?
Negative. I'm on 11.4.2
Actually. One of my servers already killed itself again on ECONNRESET, despite the error handler being added my bot is offline and doesn't respond anymore.
Updated to 0d9bc8664dc2dc3b3bf7d35ba7b9050f2797a211 now.
Bot crashes at start because fetchMessages is undefined which I use to catch up to missed messages after bot crashes.. Gotta figure out how to fix that.
Will report back.
Edit: bot running now. Will wait and see.
Bot usually dies in 1-2 hours. So if it still runs tomorrow morning, then master branch is fixed.
11.4.2 here as well
Okey 2 days later. My bot just died because Discord itself went down :D
So seems like master branch is working fine. What's weird though is that after I switched server 2 over to master branch, server 1 also stopped getting disconnects :D
Thanks for the tip, I'm happy now.
Most helpful comment
Catching the error worked, it no longer stops responding, so I'll close this.
However, I would argue that this should be handled by the library. The way it works seems backwards. I would think it would at least try to reconnect by default, and I would catch the error if I wanted to handle it myself (and not reconnect) or handle it after a few attempts.