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

The process refuses to quit. #539

Open
UchihaYuki opened this issue Nov 11, 2021 · 6 comments
Open

The process refuses to quit. #539

UchihaYuki opened this issue Nov 11, 2021 · 6 comments

Comments

@UchihaYuki
Copy link

I'm using java:0.12.2, and running on Windows 10. After executing the following code:

const java = require("java")
const ArrayList = java.import("java.util.ArrayList");
console.log(new ArrayList().sizeSync())

The process doesn't exit. Is there a java.destroy() or something?

@jjuzna
Copy link

jjuzna commented May 12, 2022

I am having the same issue, this is my example (but having issue with much bigger codebase, this is just my minimal example).

const java = require('java');
const out = java.getStaticFieldValue("java.lang.System", "out");
java.callMethodSync(out, "println", "Hello from JAVA!");

If I use npm install [email protected] everything is OK, but with version [email protected] is doesn't quit the process.
Tested with

  • Win10/java 1.8.0_201
  • node:14.19.1 + openjdk 1.8.0_322 + debian9 (container)
  • node:16.15.0 + openjdk 11.0.15 + debian10 (container)
>npm install [email protected] --save-dev
>node test.js
Hello from JAVA!
>npm install [email protected] --save-dev
>node test.js
Hello from JAVA!
....

@jjuzna
Copy link

jjuzna commented May 13, 2022

A single line example

var java = require('java');

And the issue can be recreated when following Docker section of readme.md

@jjuzna
Copy link

jjuzna commented May 17, 2022

I did some more research. The root problem is adding uv_async_init line in commit bc557ad101909990e2d4c

This call creates and runs handler that never quits so the node process continues to run. Previous version placed callbacks directly to queue that was processed by main thread. The commit message is very useful and explains why this was done this way, but unfortunately there is no "exit" event.

The only workaround that I found is scorched earth approach - call process.exit(0) - this will kill all - including other ongoing tasks (Promise...) - and exit.

@Tomas2D
Copy link

Tomas2D commented May 18, 2022

As a workaround, you can create a fork process and then kills it. This would prevent crashing the main process.

jjuzna pushed a commit to jjuzna/node-java that referenced this issue May 18, 2022
It breaks the internal indefinite loop and allows Node process to quit without SIGTERM.

 Solves bug joeferner#539 - The process refuses to quit.
@jjuzna
Copy link

jjuzna commented May 18, 2022

I've created a fork (and merge request) that adds stop() function to java object. That function closes handle used in loop spawned by uv_async_init and after that Node process can quit normally.

const java = require('java');
const out = java.getStaticFieldValue("java.lang.System", "out");
java.callMethodSync(out, "println", "Hello from JAVA!");
java.stop();

@Vitorgus
Copy link

I have the same issue with version 0.14.0, and the proposed pull request #555 still seem to be open. Are there any plans on merging it?

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

4 participants