You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
wamp,transport: add Peer.Done() for cooperative shutdown; idempotent Close
Adds a Done() <-chan struct{} method to the wamp.Peer interface.
Done is closed when Close is called, before the channel returned
by Send is closed. Senders that may race with Close can now select
on both Send and Done to detect peer closure cooperatively:
select {
case peer.Send() <- msg:
case <-peer.Done():
return // peer is closing; abandon
}
The previous contract was: bare `peer.Send() <- msg` racing with
Close panics with "send on closed channel". That hazard is now
documented in the Peer interface doc and an opt-in safe pattern
is provided. (Migrating call sites to the cooperative pattern is
a follow-up; the realm-shutdown path in router/realm.go already
serialises Close with sends via its actor goroutine, so the
panic vector there is structural rather than user-facing.)
Also makes Close idempotent on all three peer implementations
(localPeer, rawSocketPeer, websocketPeer) via sync.Once. Calling
Close more than once is now a safe no-op rather than a "close of
closed channel" panic. The previous implementations either had no
guard at all (localPeer, rawSocketPeer) or a racy
select-with-default early-out (websocketPeer).
Tests:
- transport: TestLocalPeerDoneClosesOnClose,
TestLocalPeerDoneIndependentPerSide,
TestLocalPeerCloseIdempotent — pin the Done() and idempotency
contract on localPeer.
- transport: existing TestCloseWebsocketPeer continues to verify
websocketPeer Close idempotency (now genuinely safe via
sync.Once instead of the previous racy select).
Test scaffolding (testPeer in router/broker_test.go and
wamp/peer_test.go) updated to satisfy the new interface method.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments