fix: remove disconnecting WS from connections before publishing events (#984)
disconnect_ws called _clear_output_if_matches (which publishes to Redis)
while the closing WS was still in self._connections. The _stream_reader
background task could pick up the event and _fan_out would try to send
to the already-closed WS, causing "Cannot call send once a close message
has been sent."
Move the discard(ws) before the _clear_output_if_matches call, matching
the pattern already used in _close_ws_for_did. This also improves
_find_fallback_output since it won't consider the departing WS as a
fallback candidate.
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
authored by
zzstoatzz.io