Skip to content

Commit df2e8fe

Browse files
fix(browser): prevent error stream.push() after EOF (#1932)
Co-authored-by: Daniel Lando <daniel.sorridi@gmail.com>
1 parent d7553e3 commit df2e8fe

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/lib/BufferedDuplex.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class BufferedDuplex extends Duplex {
5656
this.isSocketOpen = false
5757

5858
this.proxy.on('data', (chunk) => {
59-
if (!this.destroyed) {
59+
if (!this.destroyed && this.readable) {
6060
this.push(chunk)
6161
}
6262
})

src/lib/connect/ws.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,15 @@ const browserStreamBuilder: StreamBuilder = (client, opts) => {
257257
* https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/message_event
258258
*/
259259
async function onMessage(event: MessageEvent) {
260+
if (!proxy || proxy.destroyed || !proxy.readable) {
261+
return
262+
}
260263
let { data } = event
261264
if (data instanceof ArrayBuffer) data = Buffer.from(data)
262265
else if (data instanceof Blob)
263266
data = Buffer.from(await new Response(data).arrayBuffer())
264267
else data = Buffer.from(data as string, 'utf8')
265-
if (proxy && !proxy.destroyed) {
266-
proxy.push(data)
267-
}
268+
proxy.push(data)
268269
}
269270

270271
function socketWriteBrowser(

0 commit comments

Comments
 (0)