ReconnectingWebSocket drops messages the server sends right after the handshake
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 72/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- node.js, typescript
- Ambito
- backend, networking, testing
Direzione di ricerca
Start with src/websocket/reconnectingWebSocket.ts and src/api/coderApi.ts, tracing when the socket opens and when connect() registers listeners. Add a test where the server sends a message immediately on connection, as described in the issue. Done means the first message reaches subscribers on initial connect and reconnect; run the relevant WebSocket tests.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Found in review of #1128.
Problem
ReconnectingWebSocket.connect() (src/websocket/reconnectingWebSocket.ts) attaches its message listener to the underlying socket only after await this.#socketFactory() resolves. The factory, createOneWayWebSocket in src/api/coderApi.ts, resolves through waitForOpen on the open event.
The server can send its first frame in the same chunk as the handshake. ws emits it on a process.nextTick, which runs before the awaited promise resumes connect(). So that message reaches no listener, and subscribers never see it. The stream logger attached in attachStreamLogger is registered before open, so it still logs the message; only delivery is lost.
This happens on the first connect and on every reconnect.
Impact
Any stream whose server writes right after the handshake can lose its first message. For example, watchAgentMetadata can show nothing until the agent's next metadata update. I haven't checked each stream: the workspace watch, build logs and agent logs may lose their first event or backlog the same way. The SSE fallback (SseConnection) isn't checked either.
Repro
A plain ws 8.22.0 client against a server that sends one message on connection. The client resolves a promise on open, awaits it, then adds its message listener, mirroring connect():
listener after awaited open: 20/20 dropped
listener before open: 0/20 dropped
Script
import { WebSocket, WebSocketServer } from "ws";
const server = new WebSocketServer({ port: 0 });
server.on("connection", (socket) => socket.send("initial"));
await new Promise((resolve) => server.once("listening", resolve));
const url = `ws://127.0.0.1:${server.address().port}`;
async function attempt(listenFirst) {
const socket = new WebSocket(url);
let received = false;
const onMessage = () => (received = true);
if (listenFirst) socket.on("message", onMessage);
await new Promise((resolve, reject) => {
socket.once("open", resolve);
socket.once("error", reject);
});
if (!listenFirst) socket.on("message", onMessage);
await new Promise((resolve) => setTimeout(resolve, 100));
socket.terminate();
return received;
}
for (const listenFirst of [false, true]) {
let dropped = 0;
for (let i = 0; i < 20; i++) if (!(await attempt(listenFirst))) dropped++;
console.log(`${listenFirst ? "before" : "after awaited"} open: ${dropped}/20 dropped`);
}
server.close();
Fix
Attach the message (and other) listeners before the socket opens. For example, have the factory return the socket unopened and let connect() wait for open after registering its listeners, or have OneWayWebSocket buffer messages until a listener is attached. Add a test where the server sends a message as soon as the connection opens.
- Lingua principale
- TypeScript
- Stelle
- 132
- Fork
- 48
- Merge medio
- 2g 5h
- PR unite (30g)
- 19
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
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 coder/vscode-coder
-
bug tech-debt
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
coder/vscode-coder#1140 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Split commands.ts by topicApertaImprovement tech-debt vs-code
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
coder/vscode-coder#1135 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Migrate CI setup to pnpm/setupForse già presa @EhabY l’ha presa 20 giorni fa. Apertatech-debt
coder/vscode-coder#1119 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 2 giorni
-
Design the VS Code Workspaces panelForse già presa @chrifro l’ha presa 24 giorni fa. Aperta
coder/vscode-coder#1113 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 2 giorni
-
bug upstream
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
coder/vscode-coder#1087 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di coder/vscode-coder
Issue simili
-
Mondriaan
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
knaw-huc/textannoviz#709 ·
I maintainer di solito rispondono entro 1 giorno
-
Add: YRF Music NepalApertastreams:add
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
walletbeat/walletbeat#1558 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
hawk-digital-environments/HAWKI#438 ·
I maintainer di solito rispondono entro 1 giorno
-
good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
OktoLabsAI/okto-pulse#114 ·
I maintainer di solito rispondono entro 1 giorno