FG
💻 Software📡 Networking

Count of connected clients/sockets

Freshover 11 years ago
Mar 14, 20260 views
Confidence Score86%
86%

Problem

Hi, I am using `io.sockets.clients().length` to get the count of all currently connected clients, but after some time this number is way to high, many disconnected clients are still present in this array. Below an image of `io.sockets.clients().length`, plotted every 5 minutes for 24 hours. Once the count reached over ~2k, i restarted the server, about 200 to 300 clients reconnected, which is the correct count. Is this the wrong way to get the count of all connected clients? I also tried to count the connects and disconnects manually, but after one day there were more disconnects than connects, the count was negative. Related: https://github.com/LearnBoost/socket.io/issues/349

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate2 verificationsLast verified Mar 14, 2026

Solution: Count of connected clients/sockets

Low Risk

i have the same problem. and i make my number base on some var with i +1 during connect event and -1 during disconnect. (so this is not null problem) Usercount: https://skitch.com/tomekotomek/f4867/dock CPU: https://skitch.com/tomekotomek/f489w/dock MEMORY: https://skitch.com/tomekotomek/f4eyy/graph.php-747x374 BTW. it is more then performance problem it just lower our up-time to less t

84

Trust Score

2 verifications

100% success
  1. 1

    and i make my number base on some var with i +1 during connect event and -1 duri

    and i make my number base on some var with i +1 during connect event and -1 during disconnect. (so this is not null problem)

  2. 2

    https://skitch.com/tomekotomek/f4867/dock

    https://skitch.com/tomekotomek/f4867/dock

  3. 3

    https://skitch.com/tomekotomek/f489w/dock

    https://skitch.com/tomekotomek/f489w/dock

  4. 4

    https://skitch.com/tomekotomek/f4eyy/graph.php-747x374

    https://skitch.com/tomekotomek/f4eyy/graph.php-747x374

Validation

Resolved in socketio/socket.io GitHub issue #463. Community reactions: 1 upvotes.

Verification Summary

Worked: 2
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

socket.iowebsocketrealtimebug