Skip to content

Commit

Permalink
fix: Fix issue with reused send buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
freehuntx committed Nov 29, 2024
1 parent 0ce43e8 commit f4ae351
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/interceptors/WebSocket/WebSocketOverride.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ export class WebSocketOverride extends EventTarget implements WebSocket {
return
}

// We should copy the buffer in case the buffer is reused and changed by the sender
if (ArrayBuffer.isView(data)) {
const buffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)
data = Reflect.construct(data.constructor, [buffer])
} else if (data instanceof ArrayBufer) {
data = data.slice(0)
}

// Buffer the data to send in this even loop
// but send it in the next.
this.bufferedAmount += getDataSize(data)
Expand Down

0 comments on commit f4ae351

Please sign in to comment.