ReconnectingWebSocket drops messages the server sends right after the handshake
Les mainteneurs répondent en général sous 2 jours
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 72/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- node.js, typescript
- Domaine
- backend, networking, testing
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- TypeScript
- Étoiles
- 132
- Forks
- 48
- Merge moyen
- 2 j 5 h
- PR mergées (30 j)
- 19
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de coder/vscode-coder
-
bug tech-debt
Difficulté 3/5 1-2 jours Accessibilité débutants 68/100
coder/vscode-coder#1140 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
-
Split commands.ts by topicOuverteImprovement tech-debt vs-code
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
coder/vscode-coder#1135 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
-
Migrate CI setup to pnpm/setupPeut-être pris @EhabY l’a pris il y a 20 jours. Ouvertetech-debt
coder/vscode-coder#1119 · 1 commentaire · 1 personne assignée ·
Les mainteneurs répondent en général sous 2 jours
-
Design the VS Code Workspaces panelPeut-être pris @chrifro l’a pris il y a 23 jours. Ouverte
coder/vscode-coder#1113 · 3 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 2 jours
-
bug upstream
Difficulté 4/5 3-5 jours Accessibilité débutants 42/100
coder/vscode-coder#1087 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
Toutes les issues de coder/vscode-coder
Issues similaires
-
First unknown-user login after boot is one scrypt run slower than a real user's wrong passwordOuvertearea: backend bug priority: low
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
snapotter-hq/SnapOtter#2254 ·
Les mainteneurs répondent en général sous 1 jour
-
bug ticket
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
cratestack/cratestack#1154 ·
Les mainteneurs répondent en général sous 1 jour
-
server 消息处理器 cmd 分支补显式错误回报——竞态非法命令现走未处理拒绝Peut-être pris @openaddr l’a pris aujourd’hui. Ouverteready-for-agent refactor wayfinder:task
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
openaddr/dafung-web#428 ·
Les mainteneurs répondent en général sous 1 jour
-
Flaky: mongodb-memory-server 'Port already in use' when another process starts a mongod concurrentlyOuvertearea:testing bug effort:S priority:P2
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Les mainteneurs répondent en général sous 1 jour
-
lens:agent lens:process process
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
thebristolsound/birdbrain#1772 ·
Les mainteneurs répondent en général sous 1 jour