nodejs / nodejs/node

using/await using rejects bound functions and proxied callables as dispose methods

Aperta
#65,482 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

v24.x v8 engine
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

Version

v24.18.0

Platform
Microsoft Windows NT 10.0.26200.0 x64 (also reproduced on Linux x64 per downstream reports)
Subsystem

V8 / explicit resource management

What steps will reproduce the bug?
const fn = async function () { console.log('disposed'); };

// 1. bound function as async dispose method: throws
try {
  await using a = { [Symbol.asyncDispose]: fn.bind(null) };
} catch (e) { console.log('bound async:', e.message); }

// 2. bound function as sync dispose method: throws
try {
  using b = { [Symbol.dispose]: (function () {}).bind(null) };
} catch (e) { console.log('bound sync :', e.message); }

// 3. proxy-wrapped callable as dispose method: throws
try {
  await using c = { [Symbol.asyncDispose]: new Proxy(fn, {}) };
} catch (e) { console.log('proxied fn :', e.message); }

// 4. ordinary function: works
await using d = { [Symbol.asyncDispose]: fn };
console.log('plain fn accepted');

Output:

bound async: Symbol(Symbol.asyncDispose) is not a function
bound sync : Symbol(Symbol.dispose) is not a function
proxied fn : Symbol(Symbol.asyncDispose) is not a function
plain fn accepted
disposed
What is the expected behavior? Why is that the expected behavior?

All four cases should dispose. Per the Explicit Resource Management proposal, the dispose method is retrieved with GetMethod, which throws only when the value is neither undefined nor callable. Bound function exotic objects and proxies over callables are both callable (typeof reports "function" and they invoke fine), so rejecting them deviates from the spec. It looks like the implementation checks for a specific function instance type rather than IsCallable.

What do you see instead?

TypeError: Symbol(Symbol.asyncDispose) is not a function (respectively Symbol.dispose) at the using declaration site, for values that are callable.

Additional information

Found while debugging unjs/jiti#437: jiti's interopDefault proxy returns bound methods, so any default export with [Symbol.asyncDispose] fails under native await using while typeof mod[Symbol.asyncDispose] === 'function' reports a callable. Downstream is working around it by not binding symbol-keyed methods, but the engine behavior affects any code that binds or proxies dispose methods, which is common in DI containers and instrumentation wrappers.

If this is already tracked in the V8 tracker, a pointer would be appreciated and this can be closed as upstream.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia eseguendo la riproduzione dell’issue con Node v24.18.0 e leggendo l’implementazione di V8 / explicit resource management coinvolta nella ricerca del metodo dispose. Confronta i controlli callable per le funzioni ordinarie, associate e proxied con il comportamento di GetMethod della proposta. Il lavoro è completato quando tutti e quattro gli esempi eseguono dispose correttamente, con test di regressione per i callable associati e proxied.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, nodejs
Ambito
backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.