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

Temporary files in GZip compressed binary using native module are not removed when application uses process.exit() #52

Open
kayahr opened this issue Apr 9, 2024 · 0 comments

Comments

@kayahr
Copy link

kayahr commented Apr 9, 2024

What version of pkg are you using?

5.11.5

What version of Node.js are you using?

20.12.0

What operating system are you using?

Debian 12

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

node20-linux-x64

Describe the Bug

A GZip packaged program using a native node module and which exits with process.exit() does not remove the extracted external files from the /tmp directory. This is because the cleanup code is attached to the "beforeExit" event which is not called when process.exit is used or an exception is thrown. When attaching the cleanup code to "exit" instead then it works.

See documentation of beforeExit and exit event.

Expected Behavior

Temporary files should always be removed when program exits.

To Reproduce

  1. Create a test.js program using a native module like node-canvas (npm i canvas). Example

    const { createCanvas } = require("canvas");
    const { writeFileSync } = require("node:fs");
    const canvas = createCanvas(1024, 768);
    buffer = canvas.toBuffer();
    writeFileSync("/tmp/out.png", buffer);
    process.exit(0);
    
  2. Package the program with GZIP compression:

    pkg -C GZip test.js -t node20-linux-x64
    
  3. Run the program.

  4. Check for /tmp/pkg-* files and notice that directory was not removed.

When not using process.exit() in the test program then the directory is removed. When using exit event instead of beforeExit event in bootstrap code then tmp directory is also correctly removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant