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

async_hooks.AsyncHook hooks has extra methods #403

Closed
anonrig opened this issue Jan 29, 2025 · 6 comments · Fixed by #415
Closed

async_hooks.AsyncHook hooks has extra methods #403

anonrig opened this issue Jan 29, 2025 · 6 comments · Fixed by #415
Labels
bug Something isn't working

Comments

@anonrig
Copy link
Contributor

anonrig commented Jan 29, 2025

Environment

N/A

Reproduction

init(asyncId: number, type: string, triggerAsyncId: number, resource: any) {

AsyncHook class should not have functions that should be defined in async hook callbacks. Specifically any methods except enable and disable should be removed.

Describe the bug

async_hook polyfill is wrong.

Additional context

No response

Logs

@anonrig anonrig added the bug Something isn't working label Jan 29, 2025
@pi0 pi0 changed the title Async hook polyfill is wrong Use getters for async_hooks.AsyncHook hooks Jan 29, 2025
@pi0
Copy link
Member

pi0 commented Jan 29, 2025

Can you please provide more context why it is a bug? (is there any library that depends on this behavior)

From what I read, the class method calls this._callbacks.init.

But also can confirm async_hooks.createHook({}) seems keeping them as internal (getters?)

> async_hooks.createHook({})
AsyncHook {
  [Symbol(init)]: undefined,
  [Symbol(before)]: undefined,
  [Symbol(after)]: undefined,
  [Symbol(destroy)]: undefined,
  [Symbol(promiseResolve)]: undefined
}

@anonrig
Copy link
Contributor Author

anonrig commented Jan 29, 2025

But also can confirm async_hooks.createHook({}) seems keeping them as internal (getters?)

These are the symbols (not methods) whereas in unenv it is implemented as a method. Node.js used symbols to have "private properties" before #privateAttribute existed.

@anonrig
Copy link
Contributor Author

anonrig commented Jan 29, 2025

Here is the node.js implementation: https://github.com/nodejs/node/blob/55cc372b963af76dcbd37994f28f1a663c9298ee/lib/async_hooks.js#L75

@pi0
Copy link
Member

pi0 commented Jan 29, 2025

Yeah got it. They are extra. But what bug it causes currently?

@pi0 pi0 changed the title Use getters for async_hooks.AsyncHook hooks async_hooks.AsyncHook hooks has extra methods Jan 29, 2025
@anonrig
Copy link
Contributor Author

anonrig commented Jan 29, 2025

Yeah got it. They are extra. But what bug it causes currently?

Removing them will make a breaking change, which means that while removing this polyfill from Cloudflare Workers, we need to implement these methods even though they are not node.js compatible.

@pi0
Copy link
Member

pi0 commented Jan 29, 2025

Ah i see it is precaution. If had time do you mind to drop a PR then? 🙏🏼

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