Skip to content

Commit 8457033

Browse files
rickyescodebytere
authored andcommitted
http2: reuse ._onTimeout() in Http2Session and Http2Stream classes
PR-URL: #33354 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent eb55d9e commit 8457033

File tree

1 file changed

+26
-40
lines changed

1 file changed

+26
-40
lines changed

lib/internal/http2/core.js

+26-40
Original file line numberDiff line numberDiff line change
@@ -1460,27 +1460,7 @@ class Http2Session extends EventEmitter {
14601460
}
14611461

14621462
_onTimeout() {
1463-
// If the session is destroyed, this should never actually be invoked,
1464-
// but just in case...
1465-
if (this.destroyed)
1466-
return;
1467-
// This checks whether a write is currently in progress and also whether
1468-
// that write is actually sending data across the write. The kHandle
1469-
// stored `chunksSentSinceLastWrite` is only updated when a timeout event
1470-
// happens, meaning that if a write is ongoing it should never equal the
1471-
// newly fetched, updated value.
1472-
if (this[kState].writeQueueSize > 0) {
1473-
const handle = this[kHandle];
1474-
const chunksSentSinceLastWrite = handle !== undefined ?
1475-
handle.chunksSentSinceLastWrite : null;
1476-
if (chunksSentSinceLastWrite !== null &&
1477-
chunksSentSinceLastWrite !== handle.updateChunksSent()) {
1478-
this[kUpdateTimer]();
1479-
return;
1480-
}
1481-
}
1482-
1483-
this.emit('timeout');
1463+
callTimeout(this);
14841464
}
14851465

14861466
ref() {
@@ -1906,25 +1886,7 @@ class Http2Stream extends Duplex {
19061886
}
19071887

19081888
_onTimeout() {
1909-
if (this.destroyed)
1910-
return;
1911-
// This checks whether a write is currently in progress and also whether
1912-
// that write is actually sending data across the write. The kHandle
1913-
// stored `chunksSentSinceLastWrite` is only updated when a timeout event
1914-
// happens, meaning that if a write is ongoing it should never equal the
1915-
// newly fetched, updated value.
1916-
if (this[kState].writeQueueSize > 0) {
1917-
const handle = this[kSession][kHandle];
1918-
const chunksSentSinceLastWrite = handle !== undefined ?
1919-
handle.chunksSentSinceLastWrite : null;
1920-
if (chunksSentSinceLastWrite !== null &&
1921-
chunksSentSinceLastWrite !== handle.updateChunksSent()) {
1922-
this[kUpdateTimer]();
1923-
return;
1924-
}
1925-
}
1926-
1927-
this.emit('timeout');
1889+
callTimeout(this, kSession);
19281890
}
19291891

19301892
// True if the HEADERS frame has been sent
@@ -2202,6 +2164,30 @@ class Http2Stream extends Duplex {
22022164
}
22032165
}
22042166

2167+
function callTimeout(self, kSession) {
2168+
// If the session is destroyed, this should never actually be invoked,
2169+
// but just in case...
2170+
if (self.destroyed)
2171+
return;
2172+
// This checks whether a write is currently in progress and also whether
2173+
// that write is actually sending data across the write. The kHandle
2174+
// stored `chunksSentSinceLastWrite` is only updated when a timeout event
2175+
// happens, meaning that if a write is ongoing it should never equal the
2176+
// newly fetched, updated value.
2177+
if (self[kState].writeQueueSize > 0) {
2178+
const handle = kSession ? self[kSession][kHandle] : self[kHandle];
2179+
const chunksSentSinceLastWrite = handle !== undefined ?
2180+
handle.chunksSentSinceLastWrite : null;
2181+
if (chunksSentSinceLastWrite !== null &&
2182+
chunksSentSinceLastWrite !== handle.updateChunksSent()) {
2183+
self[kUpdateTimer]();
2184+
return;
2185+
}
2186+
}
2187+
2188+
self.emit('timeout');
2189+
}
2190+
22052191
function callStreamClose(stream) {
22062192
stream.close();
22072193
}

0 commit comments

Comments
 (0)