partyserver: with hibernation off, a closing socket removes a newer connection with the same id from getConnections(), so that client stops receiving broadcasts

Đang mở Phù hợp với người mới
#430 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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ệ
typescript
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với InMemoryConnectionManager.accept và removeConnection, nơi issue xác định mục trong map và listener close/error. Kiểm tra các bài kiểm thử về thay thế kết nối và các sự kiện close bị trì hoãn, sau đó xác minh rằng việc đóng socket cũ vẫn để kết nối mới hơn khả dụng thông qua getConnections(). Hoàn tất khi kết nối thay thế tiếp tục nhận broadcast sau khi socket cũ đóng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

InMemoryConnectionManager.accept stores connections in a Map keyed by connection.id. Its close/error listener runs this.#connections.delete(connection.id) without checking that the entry is still that connection.

y-partyserver's YProvider sends one _pk (from connectionId, or nanoid(10) once per provider) on every reconnect. So a client that reconnects while the server still holds its old socket replaces the map entry. When the old socket's close arrives later, the delete removes the new, live connection. From then on getConnections() never yields it. The client keeps sending and the server keeps applying its updates, but no broadcast reaches it: with y-partyserver that is every document update and every awareness change from the other peers. Nothing tells the client, and the provider has no watchdog for a silent socket, so it stays deaf until it reconnects for some other reason.

Repro (partyserver 0.5.10, y-partyserver 2.2.0, wrangler 4.159.0, compatibility date 2026-11-01, hibernate: false, via unstable_startWorker). A and B are YProviders in one room:

  1. Open a raw WebSocket to the room with ?_pk=<A.provider.id>. It stands in for an old socket the server has not seen die yet.
  2. Connect A, then terminate the raw socket and wait 1.5 s.
  3. A's updates still reach B. But within 3 s, none of these reach A: B's updates, B's awareness change, and the updates of a newcomer C.

The result is the same when the raw socket opens after A. Without the raw socket, all of these checks pass.

Suggested fix: in removeConnection, delete only when this.#connections.get(connection.id) === connection. The older socket then leaves the map as soon as it is replaced, which fits: it is the stale one.

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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của cloudflare/partykit

Tất cả issue của cloudflare/partykit

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.