-
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
TelemetryClient keeps handles open #935
Comments
Have you tried disabling statsbeat? That's what was holding on to things in our jest tests. microsoft/react-native-windows#9801 Try disabling it via the environment variable: set APPLICATION_INSIGHTS_NO_STATSBEAT=true Related bug? #943 |
At first, that didn't seem to work for me. Digging a bit deeper, it seems as if this might have been the culprit: ApplicationInsights-node.js/Library/Config.ts Line 118 in c060888
And in turn, this part of the
My hunch was that this was done when first initializing the client and that it took some time, at the very least longer than my test took to complete. I added a sleep at the end of the test for 5s to give the call some time (1s wasn't enough) and sure enough, the open handled went from being from the I think the issue here is, in part, the one you already linked. But also, why there's no mechanism to either gracefully wait for the client to be up and running, or wait for the client to have fully flushed. My assumption is that flushing should require an id from the correlation manager and one could therefore argue that calling |
I tried to log the |
We had a workaround here to kill the CorrelationIdManager: microsoft/react-native-windows@b6f8fd9#diff-aee83d950f58adead81e3eb030b6e4af2d177e679cd9a2abd216e009ba2c3e0bL44 I took it out because the bug was supposed to be fixed, but now I'm seeing that my tests are flaky again. |
Apparently, the open handles are basically HTTP requests that we send immediately when the TelemetryClient is instantiated, keepAlive=true in CorrelationIdManager was causing issues because the HTTP connection remain open for some time, even minutes, looks like in this case the test is faster than the actual HTTP call to be finished @alexg-axis if you wait one or two seconds is the handle gone? |
Yes, that seems as exactly what's going on here. Waiting for some seconds does let the |
We could add a shutdown functionality in the TelemeryClient that actually wait for these requests, allowing you to wait for it on your tests, let me know if this will work for everyone, @alexg-axis, @jonthysell |
That sounds like a great solution for my use case at least. |
Yes, an explicit shutdown function we could wait on would be great. |
I was able to mitigate this by wrapping appInsights initialization in an env check, and then exporting the defaultClient from the module as TelemetryClient | undefined. Setting all the options for automatic dependency collection etc to false didn't prevent the handle being opened. I was hoping appInsights.dispose() would have cleaned up sufficiently. |
Here is my code to disable AppInsights when running inside of Jest
|
☝️ This unblocked me. |
Hi everyone, |
When running some code in a test using the
TelemetryClient
, Jest detects open handles.Here's a basic replication which causes the issue.
If run using the
--detectOpenHandles
flag, the following error will be thrown.I assumed this had to do with the use of a
https.Agent
internally and tried to specify one without any keep alive, but that didn't help.I also tried to call the
dispose
function from the package, but as suspected that didn't help. I assume it's only applicable when using the default client andappInsights.setup()
.Is there any way to cleanly dispose of a
TelemetryClient
?The text was updated successfully, but these errors were encountered: