FG
📡 Networking

xhr.abort on disconnect not sending connection close to server on beforeunload event

Freshover 13 years ago
Mar 14, 20260 views
Confidence Score89%
89%

Problem

Is any body else running into this issue? Here is the scenario: 1. We are running node/socket.io on a separate server with its own DNS/domainname (Don't ask why) and our application server is on a different host/DNS/domainname. 2. The socket.io.js file is rendered from the node server. 3. When a user navigates away from a page we would like to send a disconnect event to the server from client. (Should be pretty easy right?) 4. Upon debugging we found that on line 3436 in socket.io.js an xhr.abort command is issued which should tell the server to initiate a disconnect event. (But no dice). 5. The disconnect finally fires but not from the unload event, but from the connection timeout. 6. Seems pretty simple, anyone else having these issues? Thanks.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate1 verificationLast verified Mar 14, 2026

Solution: xhr.abort on disconnect not sending connection close to server on beforeunload event

Low Risk

As much I don't like the solution and was hoping someone would provide a more "elegant" solution, at this time just sending an synchronous disconnect on the window unload event does the trick but that is a definitely a hack job solution.

84

Trust Score

1 verification

100% success
  1. 1

    As much I don't like the solution and was hoping someone would provide a more "e

    As much I don't like the solution and was hoping someone would provide a more "elegant" solution, at this time just sending an synchronous disconnect on the window unload event does the trick but that is a definitely a hack job solution.

Validation

Resolved in socketio/socket.io GitHub issue #461. Community reactions: 0 upvotes.

Verification Summary

Worked: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

socket.iowebsocketrealtimebug