partysocket: failed connections are reported as a clean close with code 1000, so `shouldReconnectOnClose` stops reconnecting
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, typescript
- Lĩnh vực
- backend, networking
Hướng nghiên cứu
Bắt đầu với packages/partysocket/src/ws.ts, đặc biệt là _handleError và _disconnect, mà issue xác định là nguồn có khả năng gây ra sự kiện close tổng hợp. So sánh sự kiện close được gửi đi với sự kiện close của WebSocket nền trong các trường hợp kết nối thất bại và kết nối bị ngắt. Thêm hoặc cập nhật kiểm thử cho các trường hợp đó; hoàn thành khi sự kiện báo mã lỗi của kết nối nền và shouldReconnectOnClose cho phép thử kết nối lại.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
When a connection attempt fails or an open connection drops (server down, network lost), PartySocket dispatches a close event with code: 1000, wasClean: true and reason: "unknown reason", and dispatches it before the error event. The underlying WebSocket reports 1006 / wasClean: false. Because the same synthetic event is passed to the new shouldReconnectOnClose option, a predicate like e => e.code !== 1000 ("reconnect unless the server closed normally") turns reconnection off the first time the server is unreachable.
Reproduction (npm i [email protected], Node 26, nothing listening on port 9):
// repro.mjs
import WebSocket from "partysocket/ws";
// Nothing listens on this port, so every attempt fails.
const ws = new WebSocket("ws://127.0.0.1:9", undefined, {
minReconnectionDelay: 100,
// Reconnect unless the server closed normally.
shouldReconnectOnClose: (e) => e.code !== 1000,
});
ws.addEventListener("close", (e) => console.log("close", e.code, e.wasClean, e.reason));
ws.addEventListener("error", () => console.log("error"));
setTimeout(() => {
console.log("shouldReconnect", ws.shouldReconnect, "retryCount", ws.retryCount);
process.exit(0);
}, 2000);
node repro.mjs
Actual:
close 1000 true unknown reason
error
shouldReconnect false retryCount 0
Expected: the close event carries the real code (close 1006 false, which is what new WebSocket("ws://127.0.0.1:9") itself reports), the predicate returns true, and the socket keeps retrying.
The same happens when an established connection is dropped without a close frame (server process killed): the user sees close 1000 true and no reconnect.
Tested with partysocket 1.3.0 and main (cloudflare/partykit f0a2e97d; packages/partysocket/src/ws.ts last changed in 6b977426), on Node 24.22.2, Node 26.13.0 and Bun 1.4.4.
Likely cause: _handleError calls this._disconnect(undefined, ...), so _disconnect(code = 1000, reason) synthesizes new CloseEvent(1000, ...) and removes the listeners, so the real close event from the socket is never seen.
Credit: https://ucsbplse.github.io/
- Ngôn ngữ chính
- TypeScript
- Star
- 1.3k
- Fork
- 84
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của cloudflare/partykit
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
cloudflare/partykit#430 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
cloudflare/partykit#429 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
cloudflare/partykit#425 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
cloudflare/partykit#424 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
cloudflare/partykit#423 ·
Tất cả issue của cloudflare/partykit
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: create_app refuses the Assistant Inbox spec as 'looks like an API key' (nesting deeper than 8)Đang mởagent:claude agent:ready dogfood type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
opennextjs/opennextjs-cloudflare#1485 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement lane: fast tier: should-stable
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
unicef/adt-studio#1078 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
WenyuChiou/agent-board#1283 ·
Maintainer thường phản hồi trong vòng 1 ngày