ReconnectingWebSocket drops messages the server sends right after the handshake
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 72/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- node.js, typescript
- 領域
- backend, networking, testing
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- TypeScript
- スター
- 132
- フォーク
- 48
- 平均マージ
- 2日 5時間
- マージ済み PR(30日)
- 19
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
coder/vscode-coder のほかの issue
-
bug tech-debt
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
coder/vscode-coder#1140 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
Improvement tech-debt vs-code
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
coder/vscode-coder#1135 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
Migrate CI setup to pnpm/setup対応中かも @EhabY が 20 日前に担当しました。 オープンtech-debt
coder/vscode-coder#1119 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
Design the VS Code Workspaces panel対応中かも @chrifro が 23 日前に担当しました。 オープン
coder/vscode-coder#1113 · コメント 3 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
bug upstream
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
coder/vscode-coder#1087 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
coder/vscode-coder の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
lukilabs/beautiful-mermaid#160 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
rescript-lang/rescript-lang.org#1420 ·
メンテナーはふだん 2 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
chthollyphile/folia-major#520 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
databuddy-analytics/Databuddy#1106 ·
メンテナーはふだん 1 日以内に返信