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

High permanent CPU usage after calling $disconnect on a client that executed an interactive transaction before (v3.9.0+) #12516

Closed
Tracked by #12363
Valerionn opened this issue Mar 24, 2022 · 4 comments · Fixed by prisma/prisma-engines#3028
Assignees
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: $disconnect topic: interactiveTransactions
Milestone

Comments

@Valerionn
Copy link

Bug description

We often recreate our prisma client in automated tests. After each test, we call await prismaClient.$disconnect(). Starting with Prisma v3.9.0 (in Prisma v3.8.0 it works fine), this causes the node process to get very high CPU usage, stacking with each new client that disconnects, up to 100%.

After investigating the issue, I observed that this only seems to happen if the client was used to run an interactive transaction before (but it's not necessarily the last query).

grafik

How to reproduce

  1. Have prisma in your project, enable the "interactiveTransactions" preview feature
  2. Run the following script:
  let i = 0;
  while(true) {
    const x = new PrismaClient();
    console.log(++i);
    await x.$connect();
    await x.$transaction(async (prisma): Promise<void> => {
      console.log('Interactive transaction callback');
    });
    await new Promise(r => setTimeout(r, 5000));
    await x.$disconnect();
    console.log('Disconnected.');
    await new Promise(r => setTimeout(r, 5000));
    console.log('Launching next client...');
  }

The test script has pauses so you can observe the CPU usage - after "Interactive transaction callback" it's still fine, but as soon as "Disconnected" is displayed, the CPU usage of the node process increases tremendously and will stay on a high level (and will continue to increase as new clients call disconnect).

If you replace the interactive transaction with something different (e.g. a "normal" transaction), then the CPU usage will stay low.

Expected behavior

CPU usage should not skyrocket when disconnecting from a client after running an interactive transaction.

Prisma information

Environment & setup

  • OS: Windows
  • Database: PostgreSQL
  • Node.js version: v16.13.1

Prisma Version

prisma                  : 3.11.0
@prisma/client          : 3.11.0
Current platform        : windows
Query Engine (Node-API) : libquery-engine b371888aaf8f51357c7457d836b86d12da91658b (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli b371888aaf8f51357c7457d836b86d12da91658b (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core b371888aaf8f51357c7457d836b86d12da91658b (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt b371888aaf8f51357c7457d836b86d12da91658b (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash    : b371888aaf8f51357c7457d836b86d12da91658b
Studio                  : 0.458.0
Preview Features        : interactiveTransactions
@Valerionn Valerionn added the kind/bug A reported bug. label Mar 24, 2022
@matthewmueller matthewmueller added topic: interactiveTransactions bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Mar 24, 2022
@janpio janpio added team/client Issue for team Client. topic: $disconnect labels Mar 24, 2022
@millsp millsp mentioned this issue May 5, 2022
10 tasks
@garrensmith
Copy link
Contributor

@Valerionn sorry for the really slow response on this. We think we have figured out the issue.
Could you run your tests or the test script with the following environmental variable set: CLOSED_TX_CLEANUP=0

@Valerionn
Copy link
Author

@garrensmith I just tested it - running the test script with CLOSED_TX_CLEANUP=0 works correctly and the CPU usage does not rise when the environment variable is set to 0.

@garrensmith
Copy link
Contributor

Great news. Thanks for confirming that for us. We will work on a better fix for that but in the meantime, you can use that workaround.

@Weakky
Copy link
Member

Weakky commented Jul 1, 2022

Hey @Valerionn, we've just fixed the issue. It should be available in the next Prisma release (4.1.0).

Thanks for reporting 🙏

@janpio janpio added this to the 4.1.0 milestone Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: $disconnect topic: interactiveTransactions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants