FG
📡 Networking

Changing query parameter issue

Freshabout 5 years ago
Mar 14, 20260 views
Confidence Score88%
88%

Problem

I am hoping I can get some direction on this. Initializing the io with io(url,opts) works with the query parameter. If that query parameter needs to change you can dot into the sio.io.opts object. However, after it is changed that way, it is not able to be changed again. Iteration 0 - Works On Initialization <code> socket = io(options.socket,{query: {_accessToken: 'cow'} }); </code> Server's socket.request._query._accessToken returns 'cow' Iteration 1 -Works When changed the first time <code> socket.io.opts.query._accessToken = 'moo'; </code> Server's socket.request._query._accessToken returns 'moo' Iteration 2 - Doesn't work anymore <code> socket.io.opts.query._accessToken = 'twomoos'; </code> Server's socket.request._query._accessToken returns 'moo'' Although it seems to change on the client side, the server still returns the value of the access token in Iteration 1. Doing some digging, I found that the <code> socket.io.engine.transport.ws </code> contains the URL for the request, but keeps the _accessToken as the iteration 1 variable. <code> ws://192.168.1.8/socket.io/?_accessToken=moo&transport=websocket&sid=mY9rC4km7ASypgDTAAAI </code> I can't change the variable using javascript because it still stays the same. That also seems rather hacky and I'd like to not do that. I haven't put in an issue request for anything, so I hope this counts as a legitimate one.

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: Changing query parameter issue

Low Risk

So I found one of the ways to resolve this as a workaround is to create a new io.Manager and pass in the new token (after I do socket.destroy() on the original object as a test) <code> socket = io(options.socket); [code block] </code> This seems to effectively reconnect and change the token each time (or any other query params). I don't know if this is what you are supposed to do since most a

84

Trust Score

1 verification

100% success
  1. 1

    So I found one of the ways to resolve this as a workaround is to create a new io

    <code> socket = io(options.socket);

    text
    socket.io = new io.Manager(options.socket,{query: {_accessToken: $auth.getToken()} });
  2. 2

    This seems to effectively reconnect and change the token each time (or any other

    This seems to effectively reconnect and change the token each time (or any other query params). I don't know if this is what you are supposed to do since most articles I read suggest changing the opts.query

  3. 3

    Hoping to get some insight or see if we can find if its a bug?

    Hoping to get some insight or see if we can find if its a bug?

Validation

Resolved in socketio/socket.io GitHub issue #1677. 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.iowebsocketrealtime