Socket.io-client: Invalid namespace error (only on Linux Ubuntu)

Created on 13 Oct 2016  ·  16Comments  ·  Source: socketio/socket.io-client

I have a NodeJS script meant to run on a device, and an app on a server. I want to connect the device to the /device namespace on the server. This works perfectly on Windows. On Ubuntu however the device just never connects. Passing a DEBUG env variable in gives this output:

socket.io-client:url parse http://localhost:3000/device +0ms
  socket.io-client new io instance for http://localhost:3000/device +7ms
  socket.io-client:manager readyState closed +5ms
  socket.io-client:manager opening http://localhost:3000/device +0ms
  engine.io-client:socket creating transport "websocket" +3ms
  engine.io-client:socket setting transport websocket +47ms
  socket.io-client:manager connect attempt will timeout after 20000 +2ms
  socket.io-client:manager readyState opening +4ms
  engine.io-client:socket socket receive: type "open", data "{"sid":"oYxMG7iQuy2Rp7LWAAAN","upgrades":[],"pingInterval":25000,"pingTimeout":60000}" +51ms
  engine.io-client:socket socket open +1ms
  socket.io-client:manager open +1ms
  socket.io-client:manager cleanup +1ms
  socket.io-client:socket transport is open - connecting +1ms
  socket.io-client:manager writing packet {"type":0,"query":"deviceId=123456789abcdef","nsp":"/device"} +1ms
  socket.io-parser encoding packet {"type":0,"query":"deviceId=123456789abcdef","nsp":"/device?deviceId=123456789abcdef"} +0ms
  socket.io-parser encoded {"type":0,"query":"deviceId=123456789abcdef","nsp":"/device?deviceId=123456789abcdef"} as 0/device?deviceId=123456789abcdef +1ms
  engine.io-client:socket flushing 1 packets in socket +1ms
  engine.io-client:socket socket receive: type "message", data "0" +14ms
  socket.io-parser decoded 0 as {"type":0,"nsp":"/"} +2ms
  engine.io-client:socket socket receive: type "message", data "4/device?deviceId=123456789abcdef,"Invalid namespace"" +3ms
  socket.io-parser decoded 4/device?deviceId=123456789abcdef,"Invalid namespace" as {"type":4,"nsp":"/device?deviceId=123456789abcdef","data":"Invalid namespace"} +2ms

I.e. the namespace seems to be invalid. I have no idea why, as this code runs perfectly on Windows.
My device (client) code:

const socket = io.connect('http://localhost:3000/device', {
    transports: ['websocket'],
    secure: true,
    query: { deviceId: '123456789abcdef' }
});

socket.on('connect', function() {
    console.log('Connection to server established');
})

My server code:

  const device = io.of('/device'),
      portal = io.of('/portal');

  device.on('connection', function(socket) {
      console.log('Connection made');
  })

Any ideas would be useful.

Unable to reproduce

Most helpful comment

I'm using 1.7.3 and the error is still there. Downgrading to 1.4.8 helped, but emit function seems to work differently. Is there any progress on fixing this in 1.7.3?

All 16 comments

I noticed this too in socket.io-client version 1.5.0. It seems that for some reason the value of opts.query gets appended to the namespaces name, which causes the "Invalid namespace" error.

example:

io.connect("/hello", {
  query: "foo=bar"
})

It should connect to namespace /hello but instead it tries to connect to namespace /hello?foo=bar.

I tested it in 1.4.8 and there is no error, so this bug was introduced somewhere after that. (Also I don't think this bug is related to Ubuntu specifically because I can reproduce it on Win7 and Mint Rosa.)

Ah ok that does make sense. Hm. Do you have any ideas for a remedy, or where in the repo I should be looking if I want to fix this?

No idea how to fix this, but you could downgrade to [email protected] where this bug doesn't exist, that's what I did anyway.

That might be linked to https://github.com/socketio/socket.io-client/pull/943 (and https://github.com/socketio/socket.io/pull/2422)

I tested it on v1.4.8 and it did work as expected. Then I tested it with v1.5 on just the client and it stopped working. However, installing v1.5 on the server _and_ client fixed the problem.

So it looks like the bug only happens when there is a version mismatch between client and server, but not when they both have the same version, whether that is above or below v1.5.

@Arrow7000 could you please check whether 1.6.0 fix your issue?

I'm still having this issue with v1.7.2

@stgogm are you using 1.7.2 on both the client and the server? Is that the exact same issue?

@darrachequesne Yes, I am. And the error is the same: It tries to connect to /namespace?q=value, for example, instead of connecting to /namespace and pass q as a query param.

@stgogm can you please provide a failing test case? I can't seem to reproduce: https://github.com/darrachequesne/socket.io-fiddle/tree/issue/invalid-namespace

@darrachequesne Effectively, the error went away. Maybe the backend wasn't updated at that time. Sorry for the wrong report and thanks for your time!

I'm having the same issue, where it works in client version 1.4.8 but fails in 1.5.1. (I'm running an older socket.io server version) Does this mean that the client and server version of socket.io should always match? Is that stated somewhere?

I'm using 1.7.3 and the error is still there. Downgrading to 1.4.8 helped, but emit function seems to work differently. Is there any progress on fixing this in 1.7.3?

Just came across something similar to this.. however w/o query strings. I'm simply calling io([path]) w/ path === "activities".

I have a view in my app that establishes two namespaced sockets, "/visits" and "/activities"... the "/visits" socket connects just fine. I see the "Invalid Namespace" message when attempting to connect to the "/activities" namespace.

Not sure why it's doing this. I'm following the same pattern for another view that uses "/homes" and "/visits" and both sockets are established just fine on that view.

@RavenHursT is the activities namespace properly created? (with io.of('/activities');)? Could you reproduce the issue with the fiddle here?

Yeah... mah bad.. I had forgotten to add the namespace server-side and forgot to update here. Please disregard :-/

Was this page helpful?
0 / 5 - 0 ratings