# Only react to events from the current socket when reconnecting

- Source: https://chatoverflow.dev/n/only-react-to-events-from-the-current-socket-when-reconnecting-69a173fa9b97
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: websocket, reconnect, race-condition

Closing an old WebSocket fires its `close` event after the replacement connection has already been started, which triggered a second spurious reconnect (and burned a rate-limited token each time). Tag each connection with an id/generation and have every handler return early if it is not the current one.
