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

Client.destroy fails with error #9741

Closed
TiltedToast opened this issue Jul 31, 2023 · 1 comment · Fixed by #9742
Closed

Client.destroy fails with error #9741

TiltedToast opened this issue Jul 31, 2023 · 1 comment · Fixed by #9742

Comments

@TiltedToast
Copy link

Which package is this bug report for?

discord.js

Issue description

In 14.12.0 the Client.destroy() method has been changed to be async, however it seems to have only caused more problems (at least for me).

As you can see below, I just have a couple of Event Listeners attached to the process so they can be caught and dealt with. I did try using async/await but the result is identical. The result being the following error message:

TypeError: Cannot read properties of undefined (reading 'clearHashSweeper')
    at Client.destroy (E:\coding-projects\hifumi-js\node_modules\.pnpm\discord.js@14.12.0_bufferutil@4.0.7_utf-8-validate@5.0.10\node_modules\discord.js\src\client\BaseClient.js:47:30)
    at Client.destroy (E:\coding-projects\hifumi-js\node_modules\.pnpm\discord.js@14.12.0_bufferutil@4.0.7_utf-8-validate@5.0.10\node_modules\discord.js\src\client\Client.js:248:11)
    at process.<anonymous> (E:\coding-projects\hifumi-js\src\app.ts:90:14)
    at process.emit (E:\coding-projects\hifumi-js\lib\events.js:513:28)
    at process.emit (E:\coding-projects\hifumi-js\lib\domain.js:489:12)
    at process.emit.sharedData.processEmitHook.installedValue [as emit] (E:\coding-projects\hifumi-js\node_modules\.pnpm\@cspotcode+source-map-support@0.8.1\node_modules\@cspotcode\source-map-support\source-map-support.js:745:40) {stack: 'TypeError: Cannot read properties of undefine…rce-map-support\source-map-support.js:745:40)', message: 'Cannot read properties of undefined (reading 'clearHashSweeper')'}

Not sure what's up with this, especially the part with the lib folder. Cause there's no such folder in that directory in the first place. Note that this is with ts-node, if I run the program normally as JS i get the following error:

TypeError: Cannot read properties of undefined (reading 'clearHashSweeper')
    at Client.destroy (E:\coding-projects\hifumi-js\node_modules\.pnpm\discord.js@14.12.0_bufferutil@4.0.7_utf-8-validate@5.0.10\node_modules\discord.js\src\client\BaseClient.js:47:30)
    at Client.destroy (E:\coding-projects\hifumi-js\node_modules\.pnpm\discord.js@14.12.0_bufferutil@4.0.7_utf-8-validate@5.0.10\node_modules\discord.js\src\client\Client.js:248:11)
    at process.<anonymous> (file:///E:/coding-projects/hifumi-js/dist/app.js:71:14)
    at process.emit (node:events:513:28)

Code sample

const client = new DiscordClient({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMembers,
        GatewayIntentBits.GuildEmojisAndStickers,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildMessageReactions,
        GatewayIntentBits.MessageContent,
        GatewayIntentBits.DirectMessages,
    ],
    partials: [Partials.Channel],
});

const stopSignals = ["SIGTERM", "SIGINT"];
if (process.platform === "win32") {
    stopSignals.push("SIGKILL");
}

stopSignals.forEach((signal) => {
    process.on(signal, () => {
        client
            .destroy()
            .then(() => {
                console.log("Closed Discord connection");
                process.exit(0);
            })
            .catch(console.error);
    });
});

Versions

  • discord.js 14.12.0
  • Node.js 18.16.0
  • Typescript 5.1.6
  • Windows 11 (23H2, Build 22631.2115)

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

Not applicable

Which gateway intents are you subscribing to?

Not applicable

I have tested this issue on a development release

No response

@TiltedToast
Copy link
Author

TiltedToast commented Jul 31, 2023

I looked into it a bit more and for some reason destroy() is accessing a non existent field on the REST class. It's not that the value is undefined, it's not listed in the definition at all.

    /**
     * The REST manager of the client
     * @type {REST}
     */
    this.rest = new REST(this.options.rest);
  }

  /**
   * Destroys all assets used by the base client.
   * @returns {void}
   */
  destroy() {
    this.rest.requestManager.clearHashSweeper();
    this.rest.requestManager.clearHandlerSweeper();
  }

@kodiakhq kodiakhq bot closed this as completed in #9742 Jul 31, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants