@nxtedition/nxt-undici 6.1.4 → 6.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/utils.js +13 -4
  2. package/package.json +1 -1
package/lib/utils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import cacheControlParser from 'cache-control-parser'
2
2
  import stream from 'node:stream'
3
+ import assert from 'node:assert'
3
4
  import { util } from '@nxtedition/undici'
4
5
 
5
6
  let fastNow = Date.now()
@@ -200,6 +201,7 @@ export class DecoratorHandler {
200
201
  #handler
201
202
  #aborted = false
202
203
  #errored = false
204
+ #completed = false
203
205
 
204
206
  constructor(handler) {
205
207
  if (typeof handler !== 'object' || handler === null) {
@@ -211,10 +213,13 @@ export class DecoratorHandler {
211
213
  onConnect(abort) {
212
214
  this.#aborted = false
213
215
  this.#errored = false
216
+ this.#completed = false
214
217
 
215
218
  return this.#handler.onConnect?.((reason) => {
216
- this.#aborted = true
217
- abort(reason)
219
+ if (!this.#aborted && !this.#completed && !this.#errored) {
220
+ this.#aborted = true
221
+ abort(reason)
222
+ }
218
223
  })
219
224
  }
220
225
 
@@ -232,19 +237,23 @@ export class DecoratorHandler {
232
237
 
233
238
  onData(data) {
234
239
  if (!this.#aborted && !this.#errored && data != null) {
240
+ assert(!this.#completed)
235
241
  return this.#handler.onData?.(data)
236
242
  }
237
243
  }
238
244
 
239
245
  onComplete(trailers) {
240
- if (!this.#aborted && !this.#errored) {
246
+ if (!this.#aborted && !this.#completed) {
247
+ this.#completed = true
248
+ assert(!this.#errored)
241
249
  return this.#handler.onComplete?.(trailers)
242
250
  }
243
251
  }
244
252
 
245
253
  onError(err) {
246
- if (!this.#errored) {
254
+ if (!this.#errored && !this.#completed) {
247
255
  this.#errored = true
256
+ assert(!this.#completed)
248
257
  return this.#handler.onError?.(err)
249
258
  }
250
259
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "6.1.4",
3
+ "version": "6.1.5",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",