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

Not calling unref can cause the program to not exit #724

Closed
pimeys opened this issue Sep 1, 2021 · 1 comment
Closed

Not calling unref can cause the program to not exit #724

pimeys opened this issue Sep 1, 2021 · 1 comment
Assignees
Projects

Comments

@pimeys
Copy link
Contributor

pimeys commented Sep 1, 2021

Hey, so while debugging this issue, I found out the way to cut the memory leak was to not unref the threadsafe function:

https://github.com/prisma/prisma-engines/pull/2196/files

This fixes the leak, but introduces another problem: the program will not exit cleanly. I couldn't find a good smaller reproduction, but when compiling the node api query engine with cargo build -p query-engine-node-api, copying target/debug/libquery_engine.so to somewhere with a .node ending, and running the following script:

const engine = require('./libquery_engine.so.node');

async function main() {
  const datamodel = `
      datasource db {
        provider = "postgres"
        url      = "postgresql://postgres:prisma@localhost:5432/"
      }

      generator js {
        provider        = "prisma-client-js"
      }

      model Test {
        id    Int     @id
        field String?
      }
    `;

  const conn = new engine.QueryEngine({
    datamodel: datamodel,
    logLevel: "debug",
    logQueries: true,
    configDir: "."
  }, (_err, log) => {
    console.log(log);
  });

  await conn.connect();

  const query = {
    query: `mutation { queryRaw(query: "SELECT 1") }`,
    variables: {},
  };

  console.log(conn.query(JSON.stringify(query), "{}"));

  await conn.disconnect();
}
main()

We see the program never exiting. Is it correct to remove the unref? And if so, is there a way to get a program to exit normally?

@Brooooooklyn Brooooooklyn self-assigned this Sep 1, 2021
@Brooooooklyn
Copy link
Sponsor Member

I think I've found the root cause, I'm refactoring the codes of query-engine-node-api

@Brooooooklyn Brooooooklyn added this to To do in 2.0 Sep 19, 2021
@Brooooooklyn Brooooooklyn moved this from To do to Done in 2.0 Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
2.0
Done
Development

No branches or pull requests

2 participants