Repository navigation
Send a Blob passed to WebSocket send() as a binary message - #8850
Conversation
There was a problem hiding this comment.
Superseded by the review of
276bdc66.
This review, of 3915480b
✅ Approved — I found no issues. With the compat flag on, a Blob is sent as a binary message in order with other sends; without the flag, nothing changes, and the tests and the WPT case cover both.
Not opened by the correctness review: 1 changed file it was meant to read
types/generated-snapshot/experimental/index.ts
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No issues found.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
No issues found.
⚡ Performance: ✅ LGTM
The Blob's bytes are copied once, the same way the existing ArrayBuffer send path copies its data.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: 3915480b
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8850 +/- ##
==========================================
- Coverage 67.73% 67.53% -0.20%
==========================================
Files 848 871 +23
Lines 215725 220345 +4620
Branches 32511 32955 +444
==========================================
+ Hits 146121 148814 +2693
- Misses 50404 52076 +1672
- Partials 19200 19455 +255 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
npaun
left a comment
There was a problem hiding this comment.
Does this really need a compat flag? Who's going to be complaining that we're no longer sending [object Blob] anymore?
The WHATWG WebSockets spec says send(Blob) sends the Blob's bytes as a binary message, in order with the other messages sent. workerd's send() takes an ArrayBuffer, an ArrayBufferView or a string, so a Blob is converted to a string and sent as a text message such as "[object Blob]". In this patch send() also takes a Blob. A Blob's bytes are always in memory, so send() copies them and queues them like any other binary message, which keeps the order with the send() calls around it. They count toward bufferedAmount and the isolate's external memory the same way. There is no compat flag. The one thing that changes is that send(blob), which used to send the text "[object Blob]" (or "[object Object]" on older compatibility dates), now sends the Blob's bytes as a binary message. Nothing should depend on that text. websocket-send-blob-test covers a Blob, an empty Blob, a File, a sliced Blob, ordering against string and ArrayBuffer sends, and bufferedAmount. It fails without the fix.
Send-binary-blob was disabled because send() didn't take a Blob, so the echo server never sent a binary message back and the test hung. In this patch it runs, and passes.
3915480 to
276bdc6
Compare
There was a problem hiding this comment.
✅ Approved — No issues found. A Blob passed to send() is copied and queued on the existing binary path, so send order and buffer accounting work as before, and dropping the compat flag is reasonable for a change that only replaces the "[object Blob]" text.
Not opened by the correctness review: 2 changed files it was meant to read
types/generated-snapshot/experimental/index.tstypes/generated-snapshot/index.ts
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No issues found. The Blob's bytes go through the same size accounting and bufferedAmount handling as an ArrayBuffer send.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
No issues found. The Blob case copies getData(js) into the existing binary send path. The internal Impl::send signature stays as it was, and the tests cover a Blob, an empty Blob, a File, a sliced Blob, ordering and bufferedAmount.
⚡ Performance: ✅ LGTM
The Blob's bytes are copied once, the same way the ArrayBuffer send path copies its data.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: 276bdc66
The WHATWG WebSockets spec says
send(Blob)sends the Blob's bytes as a binary message, in order with the other messages sent. workerd'ssend()takes an ArrayBuffer, an ArrayBufferView or a string, so a Blob is converted to a string and sent as a text message such as"[object Blob]". The WPT case Send-binary-blob was disabled because of this, since the echo server never sent a binary message back and the test hung.In this patch
send()also takes a Blob. A Blob's bytes are always in memory, sosend()copies them and queues them like any other binary message, which keeps the order with thesend()calls around it. They count towardbufferedAmountand the isolate's external memory the same way.There is no compat flag. The one thing that changes is that
send(blob), which used to send the text"[object Blob]"(or"[object Object]"on older compatibility dates), now sends the Blob's bytes as a binary message. Nothing should depend on that text.websocket-send-blob-testcovers a Blob, an empty Blob, a File, a sliced Blob, ordering against string and ArrayBuffer sends, andbufferedAmount. It fails without the fix. The second commit runs Send-binary-blob, which passes.