Skip to content

Commit bcdf4c8

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 7df79f4 commit bcdf4c8

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
@@ -1449,27 +1449,7 @@ class Http2Session extends EventEmitter {
14491449
}
14501450

14511451
_onTimeout() {
1452-
// If the session is destroyed, this should never actually be invoked,
1453-
// but just in case...
1454-
if (this.destroyed)
1455-
return;
1456-
// This checks whether a write is currently in progress and also whether
1457-
// that write is actually sending data across the write. The kHandle
1458-
// stored `chunksSentSinceLastWrite` is only updated when a timeout event
1459-
// happens, meaning that if a write is ongoing it should never equal the
1460-
// newly fetched, updated value.
1461-
if (this[kState].writeQueueSize > 0) {
1462-
const handle = this[kHandle];
1463-
const chunksSentSinceLastWrite = handle !== undefined ?
1464-
handle.chunksSentSinceLastWrite : null;
1465-
if (chunksSentSinceLastWrite !== null &&
1466-
chunksSentSinceLastWrite !== handle.updateChunksSent()) {
1467-
this[kUpdateTimer]();
1468-
return;
1469-
}
1470-
}
1471-
1472-
this.emit('timeout');
1452+
callTimeout(this);
14731453
}
14741454

14751455
ref() {
@@ -1894,25 +1874,7 @@ class Http2Stream extends Duplex {
18941874
}
18951875

18961876
_onTimeout() {
1897-
if (this.destroyed)
1898-
return;
1899-
// This checks whether a write is currently in progress and also whether
1900-
// that write is actually sending data across the write. The kHandle
1901-
// stored `chunksSentSinceLastWrite` is only updated when a timeout event
1902-
// happens, meaning that if a write is ongoing it should never equal the
1903-
// newly fetched, updated value.
1904-
if (this[kState].writeQueueSize > 0) {
1905-
const handle = this[kSession][kHandle];
1906-
const chunksSentSinceLastWrite = handle !== undefined ?
1907-
handle.chunksSentSinceLastWrite : null;
1908-
if (chunksSentSinceLastWrite !== null &&
1909-
chunksSentSinceLastWrite !== handle.updateChunksSent()) {
1910-
this[kUpdateTimer]();
1911-
return;
1912-
}
1913-
}
1914-
1915-
this.emit('timeout');
1877+
callTimeout(this, kSession);
19161878
}
19171879

19181880
// True if the HEADERS frame has been sent
@@ -2190,6 +2152,30 @@ class Http2Stream extends Duplex {
21902152
}
21912153
}
21922154

2155+
function callTimeout(self, kSession) {
2156+
// If the session is destroyed, this should never actually be invoked,
2157+
// but just in case...
2158+
if (self.destroyed)
2159+
return;
2160+
// This checks whether a write is currently in progress and also whether
2161+
// that write is actually sending data across the write. The kHandle
2162+
// stored `chunksSentSinceLastWrite` is only updated when a timeout event
2163+
// happens, meaning that if a write is ongoing it should never equal the
2164+
// newly fetched, updated value.
2165+
if (self[kState].writeQueueSize > 0) {
2166+
const handle = kSession ? self[kSession][kHandle] : self[kHandle];
2167+
const chunksSentSinceLastWrite = handle !== undefined ?
2168+
handle.chunksSentSinceLastWrite : null;
2169+
if (chunksSentSinceLastWrite !== null &&
2170+
chunksSentSinceLastWrite !== handle.updateChunksSent()) {
2171+
self[kUpdateTimer]();
2172+
return;
2173+
}
2174+
}
2175+
2176+
self.emit('timeout');
2177+
}
2178+
21932179
function callStreamClose(stream) {
21942180
stream.close();
21952181
}

0 commit comments

Comments
 (0)