nodejs / nodejs/node

performance.timerify(fn) behave inconsistently for sync/async functions

Aperta
#42,743 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

confirmed-bug perf_hooks
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

Version

master branch

Platform

All

Subsystem

perf_hooks

What steps will reproduce the bug?
function f1() { throw new Error() }
async function f2() { throw new Error() }
let h1 = perf_hooks.createHistogram()
let h2 = perf_hooks.createHistogram()
let g1 = perf_hooks.performance.timerify(f1, {histogram: h1})
let g2 = perf_hooks.performance.timerify(f2, {histogram: h2})
g1()
await g2()
h1.count === h2.count // expect true, actual false
How often does it reproduce? Is there a required condition?

Always

What is the expected behavior?

Timerified functions should behave consistently for whether trigger histogram.record.

What do you see instead?

Currently, normal function would not trigger histogram.record if throw; but async function (or any function which return promise) would.

Additional information

Currently, the code is like if (typeof result?.finally === 'function') return result.finally(...). It should use result.then instead, so the behavior will consistent with non-thenable result. Even we want to always trigger histogram.record, we should not use finally because thenable is only require to have then method, not finally method.

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 dal punto di ingresso perf_hooks performance.timerify e riproduci gli esempi sync e async forniti con gli istogrammi. Esamina come vengono gestite le promises restituite e gli errori generati; il lavoro è completato quando le funzioni sync timerified e le funzioni che restituiscono promises presentano un comportamento coerente nella registrazione negli istogrammi, inclusi i thenables.

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

Valutazione

Stack tecnologico
javascript
Ambito
performance
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.