@libp2p/utils 7.4.1-e7359e5f6 → 7.4.1-fc90066f8

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.
@@ -81,11 +81,21 @@ export abstract class AbstractStream extends AbstractMessageStream implements St
81
81
 
82
82
  this.readStatus = 'closing'
83
83
 
84
- await this.sendCloseRead(options)
85
-
86
- this.readStatus = 'closed'
84
+ // no more data can be read, so end iterators and emit 'end' without waiting
85
+ // for the remote to be told
87
86
  this.maybeDispatchEnd()
88
87
 
88
+ try {
89
+ await this.sendCloseRead(options)
90
+ } catch (err) {
91
+ this.log.error('failed to close readable end - %e', err)
92
+ throw err
93
+ } finally {
94
+ // unread data has been discarded so the readable end is closed even if
95
+ // the remote could not be told
96
+ this.readStatus = 'closed'
97
+ }
98
+
89
99
  this.log('closed readable end gracefully')
90
100
  }
91
101
 
@@ -126,6 +126,11 @@ export function byteStream <T extends MessageStream> (stream: T, opts?: ByteStre
126
126
  }
127
127
 
128
128
  const byteStreamOnMessageListener = (evt: StreamMessageEvent): void => {
129
+ // the underlying stream owns incoming data once we have been unwrapped
130
+ if (unwrapped) {
131
+ return
132
+ }
133
+
129
134
  if (overflow != null) {
130
135
  // the stream is being aborted after a previous overflow, ignore any
131
136
  // more data
@@ -265,6 +270,7 @@ export function byteStream <T extends MessageStream> (stream: T, opts?: ByteStre
265
270
  if (readBuffer.byteLength > 0) {
266
271
  stream.log('stream unwrapped with %d unread bytes', readBuffer.byteLength)
267
272
  stream.unshift(readBuffer)
273
+ readBuffer.consume(readBuffer.byteLength)
268
274
  }
269
275
 
270
276
  return stream