Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: Reuse ._onTimeout() to Http2Session and Http2Stream classes #33354

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 26 additions & 40 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1460,27 +1460,7 @@ class Http2Session extends EventEmitter {
}

_onTimeout() {
// If the session is destroyed, this should never actually be invoked,
// but just in case...
if (this.destroyed)
return;
// This checks whether a write is currently in progress and also whether
// that write is actually sending data across the write. The kHandle
// stored `chunksSentSinceLastWrite` is only updated when a timeout event
// happens, meaning that if a write is ongoing it should never equal the
// newly fetched, updated value.
if (this[kState].writeQueueSize > 0) {
const handle = this[kHandle];
const chunksSentSinceLastWrite = handle !== undefined ?
handle.chunksSentSinceLastWrite : null;
if (chunksSentSinceLastWrite !== null &&
chunksSentSinceLastWrite !== handle.updateChunksSent()) {
this[kUpdateTimer]();
return;
}
}

this.emit('timeout');
callTimeout(this);
}

ref() {
Expand Down Expand Up @@ -1909,25 +1889,7 @@ class Http2Stream extends Duplex {
}

_onTimeout() {
if (this.destroyed)
return;
// This checks whether a write is currently in progress and also whether
// that write is actually sending data across the write. The kHandle
// stored `chunksSentSinceLastWrite` is only updated when a timeout event
// happens, meaning that if a write is ongoing it should never equal the
// newly fetched, updated value.
if (this[kState].writeQueueSize > 0) {
const handle = this[kSession][kHandle];
const chunksSentSinceLastWrite = handle !== undefined ?
handle.chunksSentSinceLastWrite : null;
if (chunksSentSinceLastWrite !== null &&
chunksSentSinceLastWrite !== handle.updateChunksSent()) {
this[kUpdateTimer]();
return;
}
}

this.emit('timeout');
callTimeout(this, kSession);
}

// True if the HEADERS frame has been sent
Expand Down Expand Up @@ -2214,6 +2176,30 @@ class Http2Stream extends Duplex {
}
}

function callTimeout(self, kSession) {
// If the session is destroyed, this should never actually be invoked,
// but just in case...
if (self.destroyed)
return;
// This checks whether a write is currently in progress and also whether
// that write is actually sending data across the write. The kHandle
// stored `chunksSentSinceLastWrite` is only updated when a timeout event
// happens, meaning that if a write is ongoing it should never equal the
// newly fetched, updated value.
if (self[kState].writeQueueSize > 0) {
const handle = kSession ? self[kSession][kHandle] : self[kHandle];
const chunksSentSinceLastWrite = handle !== undefined ?
rickyes marked this conversation as resolved.
Show resolved Hide resolved
handle.chunksSentSinceLastWrite : null;
if (chunksSentSinceLastWrite !== null &&
chunksSentSinceLastWrite !== handle.updateChunksSent()) {
self[kUpdateTimer]();
return;
}
}

self.emit('timeout');
}

function callStreamClose(stream) {
stream.close();
}
Expand Down