-
Notifications
You must be signed in to change notification settings - Fork 141
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
unable to end node process #331
Comments
doesn't work. (applicationinsights@0.22.0 , node v6.11.0) test code: const appInsights = require("applicationinsights"); console.log(new Date()) console.log("test") appInsights.defaultClient.flush() |
It looks like the call to What you're seeing is a side effect of the autocollection features of this SDK assuming a long-running process (Typically, a server. Collection of requests/dependencies/performance counters don't typically make sense outside of a server context). You can avoid this problem by not using autocollection at all. Simply remove the call to As a bugfix, we should consider using |
The dispose() is what i had tried earlier and it failed. As said, flush() too. not using .start() does allow the process to end immediately. without .start() , without trackEvent real 0m3.059s without .start() , with a 1 to 3 calls to trackEvent real 0m18.394s |
Interesting. When I tried your code sample with dispose it closed for me. Sounds like there's some kind of race condition involved.
This is by design. The primary intention for this SDK is long-running server apps, so we do not send telemetry immediately, but buffer it into batches for efficiency. You can change this behavior by changing the batch interval. See the "Advanced configuration options" section of the readme for more details on the various batching options, but the one you probably want to change is |
cool, thanks. i missed that config. regarding dispose: could the fact i'm testing on windows have anything to do with it? i will try this on other environments too. My use case if for monitoring backend services/functions/lambdas, basically deployed serverless. The runtimes can vary a lot. |
The PR linked here (#334) addresses a few of these issues. Autocollection will no longer keep the app running longer than it would otherwise, and flushing can be used at the end of your app to allow it to close quickly. This is generally cleaner than setting the batchInterval to a short amount of time. |
Closing as the PR mentioned above has been merged. Feel free to re-open if you're still experiencing trouble with app termination after flush, in the next release. |
This is still a problem. The following script takes several minutes to exit after it is 'done'. Smash cut it down from my actual script, so probably minor bugs, but it runs and demonstrates the problem:
Output from running on Ubuntu 20.04 on WSL2 on Windows 10:
|
@cole-brown please try following code and let me know if there is any difference |
@hectorhdzg Thanks but no change from that setting: Still a few minutes before
|
@hectorhdzg , what is the status of this problem? Can AppInsights team provide some update? We are seeing the same issue, the Node.JS takes minutes (sometimes hours) finish the process that it's already completed. |
Nothing I tried worked, so I ended up just hard/ungracefully killing it after it was done and just waiting for AppInsights to notice: /**
* Do whatever clean-up/tear-down/etc is necessary to exit cleanly.
* @param {Promise.<bool>} success/failure of `start()` - used for exit code
*/
async function end(success) {
// # AppInsights is used here to send a heartbeat status to Azure.
await health.heartbeat();
// # This is where all the AppInsights clean-up that's SUPPOSED to let it die now happens...
await health.tearDown();
// We /could/ wait for 2-3 minutes for App Insights to notice it's dead and die so we can exit.
// log.debug('...Waiting for AppInsights to allow us to exit...');
// Or we can give up now.
// This is an ungraceful exit:
process.exit(success ? 0 : 1);
}
// -----------------------------------------------------------------------------
// RUN IT!
// -----------------------------------------------------------------------------
(async () => {
await end(await start());
})(); But this isn't really an ideal solution... |
Is there any update on this? It seems like there is still a problem with the Node.js sdk, I'm not able to shut it down gracefully using everything described here |
@tonescones FYI. |
in simple hello world script, after calling a call like
appInsights.setup().setInternalLogging(isDev, true).start()
the node process does not end.
The text was updated successfully, but these errors were encountered: