Skip to content

Commit

Permalink
fix(browser): prevent error stream.push() after EOF (#1915)
Browse files Browse the repository at this point in the history
Fixes #1914
  • Loading branch information
robertsLando authored Aug 1, 2024
1 parent 053a7be commit b5cc835
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/lib/BufferedDuplex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export class BufferedDuplex extends Duplex {
this.isSocketOpen = false

this.proxy.on('data', (chunk) => {
this.push(chunk)
if (!this.destroyed) {
this.push(chunk)
}
})
}

Expand Down
4 changes: 3 additions & 1 deletion src/lib/connect/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ const browserStreamBuilder: StreamBuilder = (client, opts) => {
let { data } = event
if (data instanceof ArrayBuffer) data = Buffer.from(data)
else data = Buffer.from(data as string, 'utf8')
proxy.push(data)
if (!proxy?.destroyed) {
proxy.push(data)
}
}

function socketWriteBrowser(
Expand Down

0 comments on commit b5cc835

Please sign in to comment.