oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.26k stars 2.69k forks source link

Websocket: Protocol error - control frame is fragmented #7775

Open yemreak opened 9 months ago

yemreak commented 9 months ago

What version of Bun is running?

1.0.18+36c316a24

What platform is your computer?

Darwin 23.2.0 arm64 arm

What steps can reproduce the bug?

I'm still encountering the Protocol error - control frame is fragmented error sometimes while connecting to the Whitebit order book via websocket. Has anyone else experienced this issue? #4101 #1592

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

yemreak commented 9 months ago

6686

Electroid commented 9 months ago

Could you provide a code sample where you're able to see this issue?

yemreak commented 9 months ago

Let me transfer the relevant part of my code here for the issue @Electroid

...

protected createWSAddress() {
  return "wss://api.whitebit.com/ws"
}

getWebsocketHeaders(): Headers | undefined {
  return
}

private async createSocket(
  socketId: SocketId,
  options?: AddressOptions
): Promise<WebSocket> {
  const address = this.createWSAddress(options)
  const socket = new WebSocket(address, { headers: this.getWebsocketHeaders() })

  return socket
}

const socketId = `orderbook${id}`
const socket = await this.createSocket(socketId, { pairSymbol })
socket.addEventListener("open", _ => {
  this.handleOrderbookSocketOpen(socketId, socket, pairSymbol)
})
socket.addEventListener("message", event => this.handleMessage(event, socketId))
socket.addEventListener("close", event =>
  this.handleSocketClose(socketId, event, () => this.watchOrderbooks(id, pairId))
)
socket.addEventListener("error", error => this.handleSocketError(socketId, error))

private handleSocketClose(
  socketId: SocketId,
  event: CloseEvent,
  reconnect: () => void
): void {
  const detail = { event, relevantPairSymbols }
  if (event.wasClean) {
    this.log("info", `Socket ${socketId} closed cleanly, reason=${event.reason}`, detail)
  } else {
    this.log(
      "warn",
      `Socket ${socketId} connection died unexpectedly, reason=${event.reason}`,
      detail
    )
  }
  // ...
}
[00:41:54.262] WARN (whitebit): Socket orderbook0 connection died unexpectedly, reason=Protocol error - control frame is fragmented
    event: {
      "isTrusted": true
    }
yemreak commented 8 months ago

@Electroid

Electroid commented 8 months ago

Thanks, yes this is an issue with the websocket client that we will fix.

lithdew commented 7 months ago

This is likely to be fixed by https://github.com/oven-sh/bun/commit/20275aa0407cf4120077b18d332417ad7a4ee416.