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

bug: asynchookscopemanager's withAsync leak context #1013

Closed
vmarchaud opened this issue May 2, 2020 · 2 comments · Fixed by #1099
Closed

bug: asynchookscopemanager's withAsync leak context #1013

vmarchaud opened this issue May 2, 2020 · 2 comments · Fixed by #1099
Assignees
Labels
bug Something isn't working

Comments

@vmarchaud
Copy link
Member

vmarchaud commented May 2, 2020

Test case:

const scope1 = '1' as any;
const scope2 = '2' as any;

await contextManager.withAsync(scope1, async () => {
  assert.strictEqual(contextManager.active(), scope1);
  await contextManager.withAsync(scope2, async () => {
    assert.strictEqual(contextManager.active(), scope2);
    done = true;
  });
  assert.strictEqual(contextManager.active(), scope1);
});

// throw because current is '1'
assert.strictEqual(contextManager.active(), Context.ROOT_CONTEXT);

I'm starting to think that we shouldn't have gone through this road of re-implenting it ourselves. It may be worth to just bundle cls-hooked, WDYT ?
cc @open-telemetry/javascript-approvers

@vmarchaud vmarchaud added the bug Something isn't working label May 2, 2020
@vmarchaud vmarchaud self-assigned this May 2, 2020
@dyladan
Copy link
Member

dyladan commented May 2, 2020

I'm not against adding cls-hooked, but I think it only works in very new versions of node correct? I would likely prefer to add a new context manager which uses cls-hooked.

Can you please take a look at the dependency tree of cls-hooked and see what impact this would have on deployment size?

@vmarchaud
Copy link
Member Author

vmarchaud commented May 3, 2020

@dyladan Nope, cls-hooked is based on async hooks like us. The only difference is that it's API is compatible with the old CLS package and it has a fallback for node < 8.

I will check if it's worth to include it as a package or just re-use its implementation. (its only 400 LOC)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants