Commit 5335251
committed
Complete the WebSocket close handshake in webSocketClose
When a client initiated a clean close, PartyServer's `webSocketClose`
forwarded to user `onClose` but never reciprocated the peer's Close
frame, leaving the client in CLOSING until it timed out and reported
1006 (abnormal closure). The Hibernation API contract requires the
application to reciprocate on every compat date; the standard
`accept()` API requires it on compat dates before 2026-04-07 (where
the runtime's `web_socket_auto_reply_to_close` flag isn't yet active).
Both the hibernating and non-hibernating paths now reciprocate via a
shared `closeQuietly` helper in a `finally` block, after `onClose` has
run (and even when `onClose` throws synchronously or asynchronously).
Reserved close codes (1005, 1006, 1015) are normalized to 1000 so the
reciprocation can never throw `InvalidAccessError`. Calling `close()`
on an already-closed socket is a silent no-op, so user code that
already calls `connection.close()` from `onClose` is unaffected.
Adds 10 regression tests (5 hibernating + 4 non-hibernating + 1
cross-cutting) covering the headline #389 repro, peer code/reason
delivery to onClose, throwing-onClose recovery, idempotent
reciprocation when user code closes from onClose, and reserved-code
normalization. The tests fail loudly without the fix with a clear
"server-side WebSocket never reciprocated the peer's Close frame"
timeout message.
Fixes #389
Made-with: Cursor1 parent 6273c96 commit 5335251
5 files changed
Lines changed: 593 additions & 7 deletions
File tree
- .changeset
- packages/partyserver/src
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
25 | 65 | | |
26 | 66 | | |
27 | 67 | | |
| |||
515 | 555 | | |
516 | 556 | | |
517 | 557 | | |
518 | | - | |
| 558 | + | |
519 | 559 | | |
520 | 560 | | |
521 | 561 | | |
522 | 562 | | |
523 | 563 | | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
524 | 576 | | |
525 | 577 | | |
526 | 578 | | |
| |||
629 | 681 | | |
630 | 682 | | |
631 | 683 | | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
632 | 694 | | |
633 | 695 | | |
634 | 696 | | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
640 | 722 | | |
641 | 723 | | |
642 | 724 | | |
| |||
0 commit comments