Please describe the problem you are having in as much detail as possible:
No way to end the process gracefully after a invalid login.
Include a reproducible code sample here, if possible:
const Discord = require('discord.js');
const client = new Discord.Client();
client.login('your token')
.then(function() {
console.log('Good!')
}, function(err) {
console.log('Still good, as long as the process now exits.')
client.destroy()
})
Expected result:
The string 'Still good, as long as the process now exits.' is printed and the process exits gracefully as described here (The Node.js process will exit on its own if there is no additional work pending in the event loop.).
Actual result:
The string is printed but the program hangs.
Further details:
Priority this issue should have – please be realistic and elaborate if possible:
[ ] I found this issue while running code on a __user account__
Second param of then() is the same as a catch()
The bot is also not shutting down if you put client.destroy() in the success handler.
const Discord = require('discord.js');
const client = new Discord.Client();
client.login('<valid token here>')
.then(function() {
console.log('Good!')
client.destroy()
}, function(err) {
console.log('Still good, as long as the process now exits.')
client.destroy()
})
There is no way to shut it down.
process.exit();
Thank you for your suggestion, @Gawdl3y , but process.exit() has some negative consequences. Async tasks (like io to a sqllite db) might not finish which might for example lead to corruption of files.
Which is why you wait for those to finish.
I have done some debugging and during it came to the conclusion the above program does in fact exit.
It takes ~2 minutes for the program to exit:
time nvm run node ./discord_bug.js
Running node v7.9.0 (npm v4.2.0)
Login failed
Done!
real 2m2.397s
user 0m1.444s
sys 0m0.208s
At first I thought it was a setTimeout() somewhere. I acked and removed them or placed debug statements near them to see if they triggered. I also searched for 12 (with the hope of finding a place where the 2 minutes are defined in seconds or milliseconds). But no luck so far. I have not looked at any of the dependencies.
This concludes my findings so far. I do not know where to go from here.
It takes ~2 minutes for the program to exit
I have the same issue. I had asked about it in Discord but no luck as well. After some debugging I fount this. This timer is not reset after logging out.
Workaround:
// client = new Discord.Client();
client.on('disconnect', function () {
clearTimeout(client.ws.connection.ratelimit.resetTimer);
});
In addition, there is unused variable resetTime (missed 'r').
Tested on v11.1, but master branch (v12) is also affected.
Theres now a new error happening on master, and it seems to be from the new Ratelimitation handlers
And yes, it also takes ~2 minutes to clear
{ Error [TOKEN_INVALID]: An invalid token was provided.
at WebSocketConnection.client.ws.connection.once.event (C:\Users\Vlad\Desktop\hwllo\node_modules\discord.js\src\client\ClientManager.js:48:41)
at Object.onceWrapper (events.js:316:30)
at emitOne (events.js:115:13)
at WebSocketConnection.emit (events.js:210:7)
at WebSocketConnection.onClose (C:\Users\Vlad\Desktop\hwllo\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:389:10)
at WebSocket.onClose (C:\Users\Vlad\Desktop\hwllo\node_modules\ws\lib\EventTarget.js:103:16)
at emitTwo (events.js:125:13)
at WebSocket.emit (events.js:213:7)
at WebSocket.emitClose (C:\Users\Vlad\Desktop\hwllo\node_modules\ws\lib\WebSocket.js:224:10)
at _receiver.cleanup (C:\Users\Vlad\Desktop\hwllo\node_modules\ws\lib\WebSocket.js:210:41) [Symbol(code)]: 'TOKEN_INVALID' }
(node:28952) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: this.handlers[handlerID].destroy is not a function
(node:28952) [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.
Fixed in latest commit, will close this issue once it makes its way to release.
@hydrabolt that should have been done with , () => this.destory()) so that you can still .catch login
closing early (anyone reading the issue, I addressed Gus' comments in a later commit)
Most helpful comment
I have the same issue. I had asked about it in Discord but no luck as well. After some debugging I fount this. This timer is not reset after logging out.
Workaround:
In addition, there is unused variable
resetTime(missed 'r').Tested on v11.1, but master branch (v12) is also affected.