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

Dispose not removing timers and exception handlers #56

Closed
bragma opened this issue Nov 27, 2015 · 0 comments
Closed

Dispose not removing timers and exception handlers #56

bragma opened this issue Nov 27, 2015 · 0 comments
Assignees
Labels
Milestone

Comments

@bragma
Copy link

bragma commented Nov 27, 2015

As per subject, the public "dispose()" method in the main ApplicationInsights class calls "dispose()" on each internal static instances of console, exceptions, performance and requests. But in the implementation of those methods, not all resources are released. As an example:

https://github.com/Microsoft/ApplicationInsights-node.js/blob/master/AutoCollection/Exceptions.ts

class AutoCollectExceptions {
...
    public enable(isEnabled: boolean) {
        if(isEnabled) {
...
                process.on("uncaughtException", this._exceptionListenerHandle);
            }
        } else {
...
                process.removeListener("uncaughtException", this._exceptionListenerHandle);
...
            }
        }
    }

    public dispose() {
        AutoCollectExceptions.INSTANCE = null;
        // <<<<---- What about calling "this.enable(false)" here?
        this._isInitialized = false;
    }

Same goes for performance.

In my tests I use the "dispose()" method to reset AI's SDK to a pristine state. This is required because AI creates a global singleton and even reloading it with another require(), the same instance is returned due to node's module caching.
After some tests, node complains about an handler leek because handlers are added on each test.

My suggestion is to call "enable(false)" in the dispose call if you agree. I can make a PR for this if you like.

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

No branches or pull requests

3 participants