Socket.readerString corrupts UTF-8 characters split across TCP chunks
Maintainer thường phản hồi trong vòng 1 ngày
Một pull request liên quan đã được merge.
- #9487 của @jayhemnani9910 — đã merge
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- nodejs, typescript
- Lĩnh vực
- networking
Hướng nghiên cứu
Start with the reproduction in the issue and inspect packages/effect/src/socket/Socket.ts:268, where Socket.readerString decodes each item independently. Determine whether streaming decoding should apply only to byte-stream transports or also to WebSocket binary messages, especially for BOM handling, truncated input, and normal close. Add regression tests covering UTF-8 characters split across TCP chunks and the agreed WebSocket behavior.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What version of Effect is running?
effect 4.0.5, @effect/platform-node 4.0.5 (same code on main 7f32606ba)
What steps can reproduce the bug?
A TCP server sends café ☕ done one byte at a time. The client reads it with Socket.readerString over NodeSocket.makeNet:
import * as net from "node:net"
import { Effect } from "effect"
import * as Socket from "effect/socket/Socket"
import * as NodeSocket from "@effect/platform-node/NodeSocket"
const bytes = Buffer.from("café ☕ done", "utf8")
const server = net.createServer(async (c) => {
for (let i = 0; i < bytes.length; i++) {
c.write(bytes.subarray(i, i + 1))
await new Promise((r) => setTimeout(r, 5))
}
c.end()
})
await new Promise<void>((r) => server.listen(0, "127.0.0.1", r))
const { port } = server.address() as net.AddressInfo
const text = await Effect.gen(function*() {
const socket = yield* NodeSocket.makeNet({ host: "127.0.0.1", port })
const pull = yield* Socket.readerString(socket)
let text = ""
while (true) {
const r = yield* Effect.result(pull)
if (r._tag === "Failure") return text
text += r.success.join("")
}
}).pipe(Effect.scoped, Effect.runPromise)
console.log(JSON.stringify(text))
server.close()
What is the expected behavior?
"café ☕ done"
What do you see instead?
"caf�� ��� done"
Additional information
readerString creates one TextDecoder per acquisition but calls decoder.decode(item) without { stream: true } (packages/effect/src/socket/Socket.ts:268), so every chunk is decoded on its own. TCP chunk boundaries are arbitrary, so any multi-byte character can land on one. toChannelString uses the same reader, and DevTools runs NDJSON over it.
Decoding in streaming mode fixes TCP, but it changes WebSocket binary messages, which are complete on their own:
- A UTF-8 BOM is stripped from every message today; in streaming mode only from the first. Two binary messages
EF BB BF 7B 7Dgive["{}", "{}"]today and["{}", "{}"]in streaming mode. - A truncated message's leftover bytes would join the next message instead of becoming U+FFFD.
I have a fix that decodes in streaming mode and, like #9436 for Channel.decodeText, flushes incomplete trailing bytes as U+FFFD on a normal close (code 1000), with tests. Is that the behaviour you want for WebSocket too, or should streaming decode apply only to byte-stream transports? Happy to open a PR either way.
- Ngôn ngữ chính
- TypeScript
- Star
- 16.7k
- Fork
- 808
- Merge trung bình
- 10 giờ 12 phút
- Pull request đã merge (30 ngày)
- 813
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Effect-TS/effect
-
BrowserWorkerRunner: port finalizer throws when the worker global has no close() (Bun)Có thể đã có người làm @santiago-ramos-02 đã nhận 20 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Effect-TS/effect#8635 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Support {self: this} for fnUntracedCó thể làm lại được @ArjunCodess đã nhận 31 ngày trước và không có pull request nào đang mở. Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Effect-TS/effect#8101 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 32/100
Effect-TS/effect#9610 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Schema.isStringFinite (and Number string matching) takes quadratic time on long digit runsCó thể đã có người làm @magoz đã nhận hôm nay. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Schema.isBase64 / isBase64Url throw RangeError on multi-megabyte stringsCó thể đã có người làm @magoz đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 20/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Effect-TS/effect
Issue tương tự
-
area: repo priority: P2 type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
appandflow/stim#4107 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 60/100
lingdojo/kana-dojo#32859 · 1 bình luận · 5 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
code-quality refactoring
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
github/gh-aw-firewall#10364 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Merge the duplicate kaffir_corn record into sorghumCó thể đã có người làm @Crypto-Shroom đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Crypto-Shroom/Bird-Feed-Calculator#322 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
drizzle-team/drizzle-orm#6552 ·
Maintainer thường phản hồi trong vòng 2 ngày