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

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.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

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?

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.)

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.

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

@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!