Search code examples
node.jssocketsherokusocket.io

Socket.io "Session ID unknown" error on Heroku


I have a Node JS app using Socket.io deployed to heroku. I have followed the steps provided at https://devcenter.heroku.com/articles/node-websockets to setup the code properly but somehow it seems like I am unable to use Web sockets properly.

All my socket polling requests are failing with the following error.

{"code":1,"message":"Session ID unknown"}

The same code seems to be working fine when I run it locally.

Client

function createSocket() {
        socket = io();

        socket.on('connect', function () {
            socket.emit('registerUser', { userEmail: $scope.userInfo.userEmail });
        });

 socket.on('list_of_files', function (data) {
            $timeout(function () {
                $scope.fileList = data;
            });

        });
    }

Server

var io = require('socket.io')(server);

    io.sockets.on('connection', function (socket) {
        socket.on('registerUser', function (data) {
            socketClients[data.userEmail] = socket;
        });
    });

I have also enabled heroku's session affinity but still no luck


Solution

  • i know its too late but for those who still looking for the answer try adding this option on the client socket.

    {
    path: '/socket.io',
    transports: ['websocket'],
    secure: true,
    }
    

    also just for your information i'm having this problem after deploying to staging server with nginx and proxy