Skip to content

Commit

Permalink
fix: ensure onConnect is always called
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jun 14, 2024
1 parent 077531a commit 39ed50c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/core/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const { headerNameLowerCasedRecord } = require('./constants')
const invalidPathRegex = /[^\u0021-\u00ff]/

const kHandler = Symbol('handler')
const noop = () => {}

class Request {
constructor (origin, {
Expand Down Expand Up @@ -223,7 +224,7 @@ class Request {
abort(this.error)
} else {
this.abort = abort
return this[kHandler].onConnect(abort)
this[kHandler].onConnect(abort)
}
}

Expand Down Expand Up @@ -295,6 +296,14 @@ class Request {
}
this.aborted = true

if (!this.abort) {
// Make sure to always call onConnect even on errors to avoid
// a common user mistake of assuming that onConnect is always
// called before any other hook.
this.abort = noop
this[kHandler].onConnect(noop)
}

return this[kHandler].onError(error)
}

Expand Down

0 comments on commit 39ed50c

Please sign in to comment.