fix: preserve h2 queue on out-of-order completion by mcollina · Pull Request #5410 · nodejs/undici (original) (raw)
Fixes: #5404
HTTP/2 streams can complete out of order. The H2 completion path was advancing kRunningIdx and clearing kQueue[kRunningIdx], which assumes in-order completion. When a later stream completed first, this could clear the wrong request slot and leave completed/running entries misclassified. Destroy/error paths could then lose the still-running request or encounter null queue entries.
This changes H2 request finalization to remove the actual completed request from the running queue section, preserving other running requests. It also skips stale null entries defensively in destroy/error cleanup loops.
Tested with:
node --test test/issue-5404.jsnode --test test/issue-5404.js test/http2-resume-null-request.js test/http2-goaway-retry-body.js test/http2-invalid-session.jsnode --test test/http2-dispatcher.jsnode --test test/issue-5404.js test/http2-pipelining-default.jsnpm run test:h2:corenpm run lint