Skip to content

Inside prisma.$transaction: console.log(connection) crashes Node with ERR_INTERNAL_ASSERTION #19137

Closed

Description

@marnixhoh

Bug description

When logging the transactionConnection in an interactive transaction to the console, Node hangs for a long time and then crashes with an ERR_INTERNAL_ASSERTION error:

at new NodeError (node:internal/errors:399:5)
    at Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1550:10)
    at formatRaw (node:internal/util/inspect:1063:12)
    at formatValue (node:internal/util/inspect:841:10)
    at inspect (node:internal/util/inspect:365:10)
    at i.<computed> (/xxx/node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:163:12995)
    at formatValue (node:internal/util/inspect:806:19)
    at formatProperty (node:internal/util/inspect:1920:11)
    at formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1920:11)
    at formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841:10)
    at inspect (node:internal/util/inspect:365:10)
    at i.<computed> (/xxx/node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:163:12995)
    at formatValue (node:internal/util/inspect:806:19)
    at formatProperty (node:internal/util/inspect:1920:11)
    at formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1920:11)
    at formatRaw (node:internal/util/inspect:1055:9)
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

at new NodeError (node:internal/errors:399:5)
    at Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1550:10)
    at formatRaw (node:internal/util/inspect:1063:12)
    at formatValue (node:internal/util/inspect:841:10)
    at inspect (node:internal/util/inspect:365:10)
    at i.<computed> (/xxx/node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:163:12995)
    at formatValue (node:internal/util/inspect:806:19)
    at inspect (node:internal/util/inspect:365:10)
    at formatWithOptionsInternal (node:internal/util/inspect:2273:40)
    at formatWithOptions (node:internal/util/inspect:2135:10)
    at console.value (node:internal/console/constructor:340:14)
    at console.log (node:internal/console/constructor:377:61)
    at /xxx/apiApp.js:44:13
    at Proxy._transactionWithCallback (/xxx/node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:179:9419) {
  code: 'ERR_INTERNAL_ASSERTION'
}

The above error seems to be printed numerous times (my terminal output truncates it). So this is just one iteration.

How to reproduce

reproduction.js

const prisma = new PrismaClient({
  datasources: {
    db: {
      url: getConnectionUrl(),
    },
  },
})

prisma
  .$transaction((connection) => {
    console.log('1');
    console.log(connection);
    console.log('2');
  })
  .then(() => console.log('finished'));

Above, '1' will print, but no other console.log statements will fire

Expected behavior

No response

Prisma information

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: v18.16.0

Prisma Version

4.13.0

Activity

  1. added
    kind/bug
    on May 8, 2023
  2. added
    bug/1-unconfirmed
    topic: $transaction
    on May 9, 2023
  3. changed the title [-]Console.log(transactionConnection) crashes Node with ERR_INTERNAL_ASSERTION[/-] [+]Inside `prisma.$transaction`: console.log(connection) crashes Node with `ERR_INTERNAL_ASSERTION`[/+] on May 9, 2023
  4. changed the title [-]Inside `prisma.$transaction`: console.log(connection) crashes Node with `ERR_INTERNAL_ASSERTION`[/-] [+]Inside `prisma.$transaction`: `console.log(connection)` crashes Node with `ERR_INTERNAL_ASSERTION`[/+] on May 9, 2023
  5. janpio commented on May 17, 2023

    @janpio
    Contributor

    That should not happen. Still I have to ask: Why do you want to log the transaction scoped Prisma Client, in your example called connection, in our docs usually called tx?

    (I think we recently had an issue about logging the normal Prisma Client object - this is probably related)
    (Update: Found it: #18292)

  6. marnixhoh commented on May 18, 2023

    @marnixhoh
    Author

    That's a good question haha!

    I ran into this issue when I was writing a test (in Jest) which tested whether or not a particular function got called with the right arguments. Here the first argument of myFunction is the connection. That's why I'm expecting that the first argument is any(Object):

    expect(myFunction).toHaveBeenLastCalledWith(expect.any(Object), <other stuff>)
    

    In some cases, this caused my test suite to freeze and sometimes it would throw weird errors.

    So while debugging this I console.logged connection to check its value and then I realized that this was the culprit.

    PS I worked around it in my test suites by removing the connection argument from the function call before comparing:

    const arguments = myFunction.mock.calls[0].shift() // removes first argument
    expect(arguments).toEqual(<something>)
    

    I hope this helps

  7. jkomyno commented on Oct 1, 2024

    @jkomyno
    Contributor

    Hi @marnixhoh, it's been a while, but I attempted to reproduce this and here's what I got:

    • On Prisma 4.13.0, I experience ~30 seconds of delay between 1 and 2 are logged, as the stringified connection object is very large to print. The query then terminates with a PrismaClientKnownRequestError:

      PrismaClientKnownRequestError: Transaction API error: Transaction already closed: A commit cannot be executed on an expired transaction. The timeout for this transaction was 5000 ms, however 27924 ms passed since the start of the transaction. Consider increasing the interactive transaction timeout or doing less work in the transaction.
          at zt.transaction (/Users/jkomyno/work/prisma/prisma/sandbox/basic-postgres/node_modules/.prisma/client/runtime/library.js:100:1206)
          at async Proxy._transactionWithCallback (/Users/jkomyno/work/prisma/prisma/sandbox/basic-postgres/node_modules/.prisma/client/runtime/library.js:179:9433)
          at async main (/Users/jkomyno/work/prisma/prisma/sandbox/basic-postgres/index.ts:19:3) {
        code: 'P2028',
        clientVersion: '4.13.0',
        meta: {
          error: 'Transaction already closed: A commit cannot be executed on an expired transaction. The timeout for this transaction was 5000 ms, however 27924 ms passed since the start of the transaction. Consider increasing the interactive transaction timeout or doing less work in the transaction.'
    • This issue is fixed as of 5.11.0

    The only thing remaining to allow us to close this issue, is to create a regression test, so that it doesn't happen again.

  8. self-assigned this
    on Oct 1, 2024
  9. added
    bug/2-confirmed
    and removed
    bug/1-unconfirmed
    on Oct 1, 2024
  10. marnixhoh commented on Oct 1, 2024

    @marnixhoh
    Author

    @jkomyno It has been a while indeed! Nonetheless, I really appreciate your reply. 😊

    Thank you for looking into this and fixing it.

    I will keep this issue open then, so that you can close it whenever the regression test has been implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug/2-confirmedkind/bugtopic: $transactiontopic: loggingtopic: prisma-clienttopic: transaction

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions