nodejs / nodejs/node

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

Offen
#65,482 1 Kommentar 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

v24.x v8 engine
Vorherrschende Sprache
JavaScript
Sterne
122k
Forks
37.3k
Ø Merge
4 T. 2 Std.
Gemergte PRs (30 T.)
283

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die Reproduktion des Issues unter Node v24.18.0 auszuführen und die an der Suche nach der dispose-Methode beteiligte V8 / explicit resource management-Implementierung zu lesen. Vergleiche die callable checks für gewöhnliche, gebundene und proxied Funktionen mit dem GetMethod-Verhalten des Vorschlags. Erledigt ist die Aufgabe, wenn alle vier Beispiele erfolgreich disposen, mit Regressionstests für gebundene und proxied Callables.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, nodejs
Bereich
backend
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.