Skip to content

Commit

Permalink
fix: always detach socket on upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Feb 27, 2021
1 parent 2480175 commit 252b676
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
16 changes: 6 additions & 10 deletions lib/core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,17 +471,13 @@ class Parser extends HTTPParser {
socket._readableState.flowing = null
socket.unshift(head)

try {
if (!request.aborted) {
detachSocket(socket)
client[kSocket] = null

client[kQueue][client[kRunningIdx]++] = null

client.emit('disconnect', client, new InformationalError('upgrade'))
detachSocket(socket)
client[kSocket] = null
client[kQueue][client[kRunningIdx]++] = null
client.emit('disconnect', client, new InformationalError('upgrade'))

request.onUpgrade(statusCode, headers, socket)
}
try {
request.onUpgrade(statusCode, headers, socket)
} catch (err) {
util.destroy(socket, err)
}
Expand Down
20 changes: 15 additions & 5 deletions lib/core/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,39 @@ class Request {
}

onConnect (abort) {
assert(!this.aborted)
if (this.aborted) {
return
}
return this[kHandler].onConnect(abort)
}

onHeaders (statusCode, headers, resume) {
assert(!this.aborted)
if (this.aborted) {
return
}
return this[kHandler].onHeaders(statusCode, headers, resume)
}

onData (chunk) {
assert(!this.aborted)
if (this.aborted) {
return
}
assert(!this.upgrade)
return this[kHandler].onData(chunk)
}

onUpgrade (statusCode, headers, socket) {
assert(!this.aborted)
if (this.aborted) {
return
}
assert(this.upgrade)
return this[kHandler].onUpgrade(statusCode, headers, socket)
}

onComplete (trailers) {
assert(!this.aborted)
if (this.aborted) {
return
}
assert(!this.upgrade)
return this[kHandler].onComplete(trailers)
}
Expand Down

0 comments on commit 252b676

Please sign in to comment.