-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Fix leak of tokens during development builds #232
Conversation
I guess |
Woah, thanks for finding this, @bendemboski. I'll take a look. |
Derp, so we'd essentially reversed the logic for token storage. Nice catch! |
@@ -89,7 +89,7 @@ class TestWaiterImpl<T extends object | Primitive = Token> implements TestWaiter | |||
private _getCompletedOperations(token: T) { | |||
let type = typeof token; | |||
|
|||
return token !== null || (type !== 'function' && type !== 'object') | |||
return token === null || (type !== 'function' && type !== 'object') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this mistake harder to make?
I'm thinking something like:
return token === null || (type !== 'function' && type !== 'object') | |
let isFunction = type === 'function'; | |
let isObject = token !== null && type === 'object'; | |
return isFunction || isObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, how about
let isFunction = type === 'function';
let isObject = token !== null && type === 'object';
let isPrimitive = !isFunction && !isObject;
return isPrimitive ? this.completedOperationsForPrimitives : this.completedOperationsForTokens;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, seems great to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like.
The logic for choosing between the Map and WeakMap for completed operation tracking wasn't right, and the result was that everything was being added to the Map, leaking every token. For waitForPromise() the token is the promise itself, meaning the resolved values were also leaking, which can easily add up to a memory leak of epic proportions.
7b22d13
to
3494e8f
Compare
The logic for choosing between the Map and WeakMap for completed operation tracking wasn't right, and the result was that everything was being added to the Map, leaking every token. For waitForPromise() the token is the promise itself, meaning the resolved values were also leaking, which can easily add up to a memory leak of epic proportions.