Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

fix: avoid memory leaks due to undisposed promise resources#885

Merged
kjin merged 6 commits intogoogleapis:masterfrom
kjin:promise-hook
Nov 2, 2018
Merged

fix: avoid memory leaks due to undisposed promise resources#885
kjin merged 6 commits intogoogleapis:masterfrom
kjin:promise-hook

Conversation

@kjin
Copy link
Copy Markdown
Contributor

@kjin kjin commented Oct 19, 2018

Most Promise async resources require a separate promiseResolve event listener. See the inline comments for more details.

@kjin kjin requested a review from a team October 19, 2018 20:53
@ghost ghost assigned kjin Oct 19, 2018
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 19, 2018
Copy link
Copy Markdown
Contributor

@ofrobots ofrobots left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a test for leaking promise resources?

Comment thread src/cls/async-hooks.ts Outdated
// currently running.
this.contexts[id] = this.contexts[this.ah.executionAsyncId()];
} else {
} else if (this.contexts[triggerId] !== undefined) {

This comment was marked as spam.

This comment was marked as spam.

@kjin
Copy link
Copy Markdown
Contributor Author

kjin commented Oct 19, 2018

@ofrobots I have added tests. They fail when the source changes are not applied.

Comment thread src/cls/async-hooks.ts
if (type === 'PROMISE') {
if (type === 'PROMISE' && this.contexts[currentId] !== undefined) {
// Opt not to use the trigger ID for Promises, as this causes context
// confusion in applications using async/await.

This comment was marked as spam.

Comment thread src/cls/async-hooks.ts Outdated
delete this.contexts[id];
},
promiseResolve: (id: number) => {
// Some Promise async resources do not get destroyed with a destroy

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Comment thread src/cls/async-hooks.ts Outdated
// Create the hook.
this.hook = this.ah.createHook({
init: (id: number, type: string, triggerId: number, resource: {}) => {
const currentId = this.ah.executionAsyncId();

This comment was marked as spam.

This comment was marked as spam.

Copy link
Copy Markdown
Contributor

@ofrobots ofrobots left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm once you make the suggested structural improvements.

@kjin kjin merged commit 8454389 into googleapis:master Nov 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants