-
Notifications
You must be signed in to change notification settings - Fork 83
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
How to exit after calling the request? #711
Comments
Extending the script with: await main();
const activeHandles = process._getActiveHandles();
const activeRequests = process._getActiveRequests();
console.log("activeHandles", activeHandles.length, activeHandles);
console.log("activeRequest", activeRequests.length, activeRequests); shows 3 activeHandles, 2 Exits after 10m, I think its a connection pool that is keeping the script from closing. |
Thank you for your answer. If it's a connection pool, can we safely exit the program by closing the connection pool? |
Hey @luchenqun, with v0.10.0, clients keep the HTTP/2 connection alive. Node.js respects the active socket and does not exit on it's own. The default timeout for idle connections is 15 minutes. You can provide a smaller value to let your script exit earlier, for example 5 seconds: const transport = createGrpcTransport({
baseUrl: "https://demo.connect.build",
httpVersion: "2",
+ idleConnectionTimeoutMs: 5000,
}); If waiting for the idle timeout is not helpful in your use case, you can close the connection explicitly. You can find an example at the bottom of this PR description: #673 While this works as intended, it might be surprising without the context. I think we might want to unref the connection so that the code in your example would exit right away. |
The enhancement to this behavior was released in v0.12.0. The example in the description should exit on its own now. |
Describe the bug
I used Node.js to call a gRPC service with an official example. However, after executing the script, Node.js did not exit and I had to manually call
process.exit(0)
to exit. Below is the relevant JavaScript code I wrote:Environment (please complete the following information):
0.11.0
16.16.0
The program will automatically exit in about ten minutes.exited with code=0 in 611.145 seconds
The text was updated successfully, but these errors were encountered: