Skip to content

worker: set binaryType = "arraybuffer" to fix 1003 "binary messages required" - #61

Open
avost wants to merge 1 commit into
by-sonic:mainfrom
avost:patch-1
Open

avost wants to merge 1 commit into
by-sonic:mainfrom
avost:patch-1

Conversation

@avost

@avost avost commented Oct 2, 2026

Copy link
Copy Markdown

Problem

Workers deployed with a compatibility date of 2026-03-17 or later drop every tunnel immediately. The client log shows:

Сбой туннеля DC2 через <name>.workers.dev: WebSocket закрыт: 1003 binary messages required

and TGLock stays on "Ищем новый маршрут" whenever direct routes are blocked.

Cause: starting with compatibility date 2026-03-17 Cloudflare enables the websocket_standard_binary_type flag, so binary WebSocket messages are delivered as Blob instead of ArrayBuffer (changelog). The message handler accepts only ArrayBuffer / ArrayBuffer.isView, treats the Blob as a non-binary message and closes the socket with 1003.

This affects every newly created worker, and existing ones once the compatibility date is bumped (which docs/CLOUDFLARE_WORKER.md suggests for cloudflare:sockets errors).

Fix

Set server.binaryType = "arraybuffer" before server.accept(). Per Cloudflare docs this restores ArrayBuffer delivery regardless of the compatibility flag, so it is safe for both old and new compatibility dates.

const [client, server] = Object.values(new WebSocketPair());
server.binaryType = "arraybuffer";
server.accept();

Testing

  • macOS, tglock-cli with --worker, ISP blocks direct kws*.web.telegram.org (tls handshake eof).
  • Before: tunnels via the worker closed with 1003, route never established.
  • After: no 1003 errors, 7–9 stable tunnels on DC2 via Cloudflare Worker, 0 failures; Telegram works normally.

Workaround for users who can't update the code: set compatibility date ≤ 2026-03-16 or add the no_websocket_standard_binary_type compatibility flag.

…equired"

Since compatibility date 2026-03-17 Cloudflare delivers binary WebSocket messages as Blob (websocket_standard_binary_type). The message handler accepts only ArrayBuffer and closes every tunnel with 1003. Setting binaryType before accept() restores ArrayBuffer delivery regardless of the compatibility date.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant