Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Socket.readerString corrupts UTF-8 characters split across TCP chunks

Đã đóng
#9,486 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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 7D give ["{}", "{}"] 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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Effect-TS/effect

Tất cả issue của Effect-TS/effect

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.