diff --git a/lib/api/api-pipeline.js b/lib/api/api-pipeline.js index e64b3294965..322334e7848 100644 --- a/lib/api/api-pipeline.js +++ b/lib/api/api-pipeline.js @@ -145,7 +145,7 @@ class PipelineHandler extends AsyncResource { } onConnect (abort, context) { - const { ret, res } = this + const { res } = this if (this.reason) { abort(this.reason) @@ -153,7 +153,6 @@ class PipelineHandler extends AsyncResource { } assert(!res, 'pipeline cannot be retried') - assert(!ret.destroyed) this.abort = abort this.context = context diff --git a/lib/handler/decorator-handler.js b/lib/handler/decorator-handler.js index 26f220c64cd..9d2c4d0a34d 100644 --- a/lib/handler/decorator-handler.js +++ b/lib/handler/decorator-handler.js @@ -1,7 +1,13 @@ 'use strict' +const assert = require('node:assert') +const noop = () => {} + module.exports = class DecoratorHandler { #handler + #onConnectCalled = false + #onCompleteCalled = false + #onErrorCalled = false constructor (handler) { if (typeof handler !== 'object' || handler === null) { @@ -11,34 +17,60 @@ module.exports = class DecoratorHandler { } onConnect (...args) { + this.#onConnectCalled = true return this.#handler.onConnect?.(...args) } onError (...args) { + if (!this.#onConnectCalled) { + this.#onConnectCalled = true + this.#handler.onConnect?.(noop) + } + + this.#onErrorCalled = true return this.#handler.onError?.(...args) } onUpgrade (...args) { + assert(!this.#onCompleteCalled) + assert(!this.#onErrorCalled) + return this.#handler.onUpgrade?.(...args) } onResponseStarted (...args) { + assert(!this.#onCompleteCalled) + assert(!this.#onErrorCalled) + return this.#handler.onResponseStarted?.(...args) } onHeaders (...args) { + assert(!this.#onCompleteCalled) + assert(!this.#onErrorCalled) + return this.#handler.onHeaders?.(...args) } onData (...args) { + assert(!this.#onCompleteCalled) + assert(!this.#onErrorCalled) + return this.#handler.onData?.(...args) } onComplete (...args) { + assert(!this.#onCompleteCalled) + assert(!this.#onErrorCalled) + + this.#onCompleteCalled = true return this.#handler.onComplete?.(...args) } onBodySent (...args) { + assert(!this.#onCompleteCalled) + assert(!this.#onErrorCalled) + return this.#handler.onBodySent?.(...args) } }