Burak
Burak

Reputation: 5764

Cannot use socket.io with redis on Heroku

I am trying to use socket io on Heroku with RedisToGo. In local environment, everything is fine.

When I deploy my code to the Heroku, most of the time I am getting 400 Bad Request with following data from the browser:

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

My redis config is:

var url = "redis://redistogo:[email protected]:xxxx/";
var rtg   = require("url").parse(url);

var pub = redis.createClient(rtg.port, rtg.hostname, {return_buffers: true});
var sub = redis.createClient(rtg.port, rtg.hostname, {return_buffers: true});
pub.auth(rtg.auth.split(":")[1]);
sub.auth(rtg.auth.split(":")[1]);

var redisOptions = {
  pubClient: pub,
  subClient: sub,
  host: rtg.hostname,
  port: rtg.port
};

io.adapter(ioredis(redisOptions));

What is the problem?

Upvotes: 0

Views: 282

Answers (2)

kariscomp
kariscomp

Reputation: 21

Enabling session affinity on the Heroku app should fix the Session ID unknown error, you can do this by running

heroku features:enable http-session-affinity

Upvotes: 0

Burak
Burak

Reputation: 5764

The problem was Heroku accepting only websocket transport. Setting transports to websocket both in server and clients solved the problem.

Upvotes: 1

Related Questions