mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 08:13:50 +00:00
Fixes #588. Sign-out already cleared the token-refresh timers and stopped the keep-alive interval - the reported endless loops came from async callbacks that were in flight at that moment. The token refresh's failure handler re-armed its retry after logout, and a failing keep-alive ping called reconnect() -> connect(), which restarts the keep-alive and thereby revived the interval disconnect() had just stopped. Only closing the tab ended it. Two mechanisms fix that class: transiently failed token refreshes only re-arm while the account is still signed in (checked when the failure lands, not when the request started), and the client carries an intentionallyDisconnected flag set by disconnect() - the ping callback, reconnect(), the SSE reconnect scheduling and the polling fallback all stop at it, so nothing revives after an intentional sign-out. Failed retries also back off instead of hammering a down server every 30 seconds: the token refresh climbs 30s/1m/2m/5m (capped, reset on success), and the keep-alive skips upcoming ticks on consecutive failures for the same effective ladder. Recovery after an outage is unchanged in substance - the session survives and reconnects within at most ~5 minutes, immediately on user activity.