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

DeprecationWarning: Implicit coercion to integer for exit code is deprecated #17127

Closed
dionsaur84 opened this issue Jan 4, 2023 · 8 comments · Fixed by #18899
Closed

DeprecationWarning: Implicit coercion to integer for exit code is deprecated #17127

dionsaur84 opened this issue Jan 4, 2023 · 8 comments · Fixed by #18899
Assignees
Labels
kind/improvement An improvement to existing feature and code. team/client Issue for team Client.
Milestone

Comments

@dionsaur84
Copy link

dionsaur84 commented Jan 4, 2023

Bug description

i am running nodemon for an express server that uses prisma

every time nodemon restarts the server, i get this warning:

(node:14591) [DEP0164] DeprecationWarning: Implicit coercion to integer for exit code is deprecated.
    at process.exit (node:internal/process/per_thread:200:7)
    at process.<anonymous> (/Users/dionsaur84/Sites/dio-framework/node_modules/@prisma/client/runtime/index.js:27577:17)
    at Object.onceWrapper (node:events:628:26)
    at process.emit (node:events:513:28)

this warning appears to be triggered by @prisma/client/runtime/index.js:27577:17:

  installHook(event, shouldExit = false) {
    process.once(event, async (code) => {
      debug9(`exit event received: ${event}`);
      for (const listener of this.idToListenerMap.values()) {
        await listener();
      }
      this.idToListenerMap.clear();
      if (shouldExit && process.listenerCount(event) === 0) {
        process.exit(code); // <-- this line
      }
    });
  }

is there a way to surpress this? should i add an event listener for when my server closes to make sure prisma also disconects? how do i resolve this issue myself, or is it a prisma issue?

edit: i've added a $disconnect call to my server close listener and the warning still occurs:

const server = app.listen(env.APP_PORT, () => {
    console.log(`app listening on http://localhost:${env.APP_PORT}`)
})

server.on('close', async () => {
    await prisma.$disconnect()
})

final edit: looks like this is only happening in node 19+ due to this change:

https://fossies.org/diffs/node/v19.2.0_vs_v19.3.0/lib/internal/process/per_thread.js-diff.html

@dionsaur84 dionsaur84 added the kind/bug A reported bug. label Jan 4, 2023
@jkomyno jkomyno added kind/improvement An improvement to existing feature and code. team/client Issue for team Client. and removed kind/bug A reported bug. labels Jan 4, 2023
@skyrina
Copy link

skyrina commented Jan 15, 2023

can confirm

@weedz
Copy link

weedz commented Feb 3, 2023

Think this is a prisma issue. Can't seem to find documentation for this anywhere, and the type definitions for Node does not help either. The signal handler is typed as:

type SignalsListener = (signal: Signals) => void;

But the handler for Signal-event (https://nodejs.org/api/process.html#signal-events) seems to take two arguments, signal: string, code: number. Tried the following with node 19, 18 and 16:

// Begin reading from stdin so the process does not exit.
process.stdin.resume();

process.on("SIGINT", (signal, code) => {
  console.log("signal:", signal);
  console.log("code:", code);
  process.exit(128 + code);
});

(Also, process.exit("SIGINT") exits with code 0 but I would assume it should be something greater than 0, https://man7.org/linux/man-pages/man7/signal.7.html? Tested with node 16, 18, 19)

128 comes from https://nodejs.org/api/process.html#signal-events:

'SIGTERM' and 'SIGINT' have default handlers on non-Windows platforms that reset the terminal mode before exiting with code 128 + signal number

With this I guess the installHook (https://github.com/prisma/prisma/blob/main/packages/engine-core/src/library/ExitHooks.ts#L51) function should be changed to:

private installHook(event: string, shouldExit = false) {
    process.once(event, async (signal, code) => { // <-- `(code)` -> `(signal, code)`
        debug(`exit event received: ${event}`)
        for (const listener of this.idToListenerMap.values()) {
            await listener()
        }
        
        this.idToListenerMap.clear()
        
        // only exit, if only we are listening
        // if there is another listener, that other listener is responsible
        if (shouldExit && process.listenerCount(event) === 0) {
            process.exit(128 + code)  // <-- `code` -> `128 + code`, or just `0`?
        }
    })
}

@Geczy
Copy link

Geczy commented Feb 11, 2023

i have this issue as well, any solution yet for us? its crashing a highly used production app

@SuperchupuDev
Copy link

SuperchupuDev commented Apr 22, 2023

This now throws on Node 20 instead of giving a deprecation warning

TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('SIGINT')
    at __node_internal_captureLargerStackTrace (node:internal/errors:490:5)
    at new NodeError (node:internal/errors:399:5)
    at __node_internal_ (node:internal/validators:96:13)
    at process.set [as exitCode] (node:internal/bootstrap/node:124:9)
    at process.exit (node:internal/process/per_thread:188:24)
    at process.<anonymous> (/root/hee8-bot/node_modules/@prisma/client/runtime/library.js:99:2170)
    at Object.onceWrapper (node:events:626:26)
    at process.emit (node:events:511:28) {
  code: 'ERR_INVALID_ARG_TYPE'
}

related:

@jkomyno jkomyno self-assigned this Apr 27, 2023
@jkomyno jkomyno added this to the 4.14.0 milestone Apr 27, 2023
@kjenney
Copy link

kjenney commented Jul 23, 2023

Is the solution to use an older version of Node?

@kjenney
Copy link

kjenney commented Jul 24, 2023

Downgrading to node 18 got me passed the error.

@SuperchupuDev
Copy link

@kjenney no, the solution is to upgrade to prisma 4.14.0 or newer

@torchsmith
Copy link

I have the same issue in 4.16.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/improvement An improvement to existing feature and code. team/client Issue for team Client.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants