FG
📡 Networking

Safari dropping web socket connection due to inactivity when page not in focus

Freshover 4 years ago
Mar 14, 20260 views
Confidence Score77%
77%

Problem

You want to: [x] report a bug [ ] request a feature Current behaviour Not sure if this is a known issue (I tried searching but found nothing). Safari for Mac appears to be silently dropping websocket connections due to inactivity/idle if the page/tab is not in focus. Steps to reproduce (if the current behaviour is a bug) Make Safari tab/page not in focus; log websocket events. Expected behaviour Websockets should be kept alive via the heartbeat functionality. Not seeing this behavior in other browsers so unlikely to be my code. Setup - OS: Mac OSX 10.12.4 (16E195) - browser: Safari 10.1 (12603.1.30.0.34) - socket.io version: 1.7.3 Other information (e.g. stacktraces, related issues, suggestions how to fix) Is this possibly some sort of power-saving feature that is overriding/ignoring the heartbeats?

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
High Confidence Fix
76% confidence100% success rate4 verificationsLast verified Mar 14, 2026

Solution: Safari dropping web socket connection due to inactivity when page not in focus

Low Risk

@twistedpixel the reconnection delay is exponential (that is, something like: wait 500ms, try reconnect, wait 1000ms, try reconnect...) (source), so that may explain the behaviour. How about forcing to reconnect when the window gets the focus again? [code block] It may be related to https://github.com/primus/primus/issues/348.

76

Trust Score

4 verifications

100% success
  1. 1

    @twistedpixel the reconnection delay is exponential (that is, something like: wa

    @twistedpixel the reconnection delay is exponential (that is, something like: wait 500ms, try reconnect, wait 1000ms, try reconnect...) (source), so that may explain the behaviour.

  2. 2

    How about forcing to reconnect when the window gets the focus again?

    How about forcing to reconnect when the window gets the focus again?

  3. 3

    It may be related to https://github.com/primus/primus/issues/348.

    It may be related to https://github.com/primus/primus/issues/348.

Validation

Resolved in socketio/socket.io GitHub issue #2924. Community reactions: 7 upvotes.

Verification Summary

Worked: 4
Partial: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

socket.iowebsocketrealtimebug