Commit 60ba16b
committed
fix(client-h2): stop double-decrementing kOpenStreams on stream timeout
The HTTP/2 stream 'timeout' handler in lib/dispatcher/client-h2.js does:
stream.on('timeout', () => {
const err = new InformationalError(...)
stream.removeAllListeners('data')
session[kOpenStreams] -= 1
if (session[kOpenStreams] === 0) session.unref()
abort(err)
})
`abort(err)` ultimately destroys the http2 stream, which fires 'close',
and the 'close' listener a few lines above already decrements
kOpenStreams:
stream.once('close', () => {
stream.removeAllListeners('data')
session[kOpenStreams] -= 1
if (session[kOpenStreams] === 0) session.unref()
})
Result: a single timed-out request knocks the counter down twice and it
ends at -1 instead of 0. Future stream accounting on the session is then
permanently skewed (the === 0 unref check can never match, and
reused-session flows that rely on the counter reaching 0 to release the
socket start holding sessions open longer than they should).
Leave the decrement to the 'close' handler. The 'timeout' handler only
needs to stop the data listener and call abort(); destruction via abort()
guarantees 'close' fires exactly once. After this change the repro in
the issue reports `open streams after timeout: 0` as expected.
Fixes #5073
Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>1 parent c7a2901 commit 60ba16b
1 file changed
+0
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
757 | 757 | | |
758 | 758 | | |
759 | 759 | | |
760 | | - | |
761 | | - | |
762 | | - | |
763 | | - | |
764 | | - | |
765 | | - | |
766 | 760 | | |
767 | 761 | | |
768 | 762 | | |
| |||
0 commit comments