LakeYS / Discord-Trivia-Bot

TriviaBot: Play trivia in Discord! Powered by discord.js and OpenTDB, with 24 categories and three modes of play.
Apache License 2.0
84 stars 39 forks source link

Unhandled promise rejection when shard takes too long to log in ("Client took too long to become ready") #128

Closed LakeYS closed 3 years ago

LakeYS commented 6 years ago

This may be related to discord.js instead of the bot itself. Difficult to replicate.

(node:11632) UnhandledPromiseRejectionWarning: Error: Shard 0's Client took too
long to become ready.
    at Timeout.setTimeout [as _onTimeout] (C:\Content\_Dev\Discord-Trivia-Bot\no
de_modules\discord.js\src\sharding\Shard.js:89:31)
    at ontimeout (timers.js:482:11)
    at tryOnTimeout (timers.js:317:5)
    at Timer.listOnTimeout (timers.js:277:5)
    at emitWarning (internal/process/promises.js:65:17)
    at emitPendingUnhandledRejections (internal/process/promises.js:109:11)
    at runMicrotasksCallback (internal/process/next_tick.js:124:9)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
(node:11632) Error: Shard 0's Client took too long to become ready.
    at Timeout.setTimeout [as _onTimeout] (C:\Content\_Dev\Discord-Trivia-Bot\node_modules\discord.js\src\sharding\Shard.js:89:31)
    at ontimeout (timers.js:482:11)
    at tryOnTimeout (timers.js:317:5)
    at Timer.listOnTimeout (timers.js:277:5)
(node:11632) [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.
    at emitWarning (internal/process/promises.js:92:15)
    at emitPendingUnhandledRejections (internal/process/promises.js:109:11)
    at runMicrotasksCallback (internal/process/next_tick.js:124:9)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

The shard does fix itself after a few seconds, so in most cases manual action is not required until unhandled promise rejections are entirely deprecated.

The code from discord.js for reference:

  spawn(args = this.manager.args, execArgv = this.manager.execArgv) {
    this.process = childProcess.fork(path.resolve(this.manager.file), args, {
      env: this.env, execArgv,
    })
      .on('exit', this._exitListener)
      .on('message', this._handleMessage.bind(this));

    /**
     * Emitted upon the creation of the shard's child process.
     * @event Shard#spawn
     * @param {ChildProcess} process Child process that was created
     */
    this.emit('spawn', this.process);

    return new Promise((resolve, reject) => {
      this.once('ready', resolve);
      this.once('disconnect', () => reject(new Error(`Shard ${this.id}'s Client disconnected before becoming ready.`)));
      this.once('death', () => reject(new Error(`Shard ${this.id}'s process exited before its Client became ready.`)));
      setTimeout(() => reject(new Error(`Shard ${this.id}'s Client took too long to become ready.`)), 30000);
    }).then(() => this.process);
  }
LakeYS commented 5 years ago

Confirmed still occurring as of Dec 7, 2018.

LakeYS commented 3 years ago

Stale