Socket.readerString corrupts UTF-8 characters split across TCP chunks
I maintainer di solito rispondono entro 1 giorno
Una pull request collegata è già stata integrata.
- #9487 di @jayhemnani9910 — integrata
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- nodejs, typescript
- Ambito
- networking
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 16.7k
- Fork
- 808
- Merge medio
- 10h 7m
- PR unite (30g)
- 808
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Effect-TS/effect
-
Support {self: this} for fnUntracedForse già presa @ArjunCodess l’ha presa 33 giorni fa. Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Effect-TS/effect#8101 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
v4 Cache.get: a caller that joins an abandoned lookup fails with an interruption it did not ask forAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
I maintainer di solito rispondono entro 1 giorno
-
Typed unix socket and TLS options for `BunHttpClient` and `DenoHttpClient`Forse già presa @effect-bot l’ha presa 1 giorno fa. Apertadocker-made-me-do-it enhancement platform
Effect-TS/effect#9687 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
RFC 9457 Problem Details for HttpApi errorsForse già presa @effect-bot l’ha presa 1 giorno fa. Apertadocker-made-me-do-it enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Effect-TS/effect
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
phivk/rubiks-lab#33 ·
I maintainer di solito rispondono entro 1 giorno
-
BUG:Edit Album strips spaces from the password so albums with a leading/trailing space in the password can't be editedForse già presa @ManyaJain111 l’ha presa oggi. Apertabug enhancement possible-duplicate
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
AOSSIE-Org/PictoPy#1637 · 4 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
chaitin/MonkeyCode#1437 ·
I maintainer di solito rispondono entro 1 giorno
-
rtdb-info-connected-order test: unhandled 'connection is closed' rejection fails the CLI suiteAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
area:cards enhancement migration ready-for-agent
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
fil-donadoni/tolaria#6309 ·
I maintainer di solito rispondono entro 1 giorno