Jon Chu
Jon Chu

Reputation: 1937

Socket.io fails with an internal error

I recently ran and npm install, which updated all my packages. For some reason, this broke my webserver (whenever I try to load a page it only loads part way and dies with this error). I tried rolling back versions of socket.io, redis, and nodetime, which are the packages that show up in the stacktrace, but I've had no luck in getting the webserver to work again. Help? I'm running on OS X.

events.js:66
        throw arguments[1]; // Unhandled 'error' event
                       ^
TypeError: First argument must be a Buffer
    at RedisClient.message (/Users/jchu/code/python/agles/ci/web/back/node_modules/socket.io/lib/stores/redis.js:126:24)
    at RedisClient.EventEmitter.emit (events.js:115:20)
    at RedisClient.return_reply (/Users/jchu/code/python/agles/ci/web/back/node_modules/socket.io/node_modules/redis/index.js:440:22)
    at RedisReplyParser.<anonymous> (/Users/jchu/code/python/agles/ci/web/back/node_modules/socket.io/node_modules/redis/index.js:81:14)
    at RedisReplyParser.EventEmitter.emit (events.js:88:17)
    at RedisReplyParser.add_multi_bulk_reply (/Users/jchu/code/python/agles/ci/web/back/node_modules/socket.io/node_modules/redis/lib/parser/javascript.js:311:14)
    at RedisReplyParser.send_reply (/Users/jchu/code/python/agles/ci/web/back/node_modules/socket.io/node_modules/redis/lib/parser/javascript.js:272:18)
    at RedisReplyParser.execute (/Users/jchu/code/python/agles/ci/web/back/node_modules/socket.io/node_modules/redis/lib/parser/javascript.js:222:22)
    at RedisClient.on_data (/Users/jchu/code/python/agles/ci/web/back/node_modules/socket.io/node_modules/redis/index.js:358:27)
    at Socket.<anonymous> (/Users/jchu/code/python/agles/ci/web/back/node_modules/socket.io/node_modules/redis/index.js:93:14)

Upvotes: 1

Views: 443

Answers (2)

dangoldnj
dangoldnj

Reputation: 384

Unfortunately, MsgPack is required in my project so I couldn't use the answer listed here.

Instead, I found this page: https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO

Which led me to these code changes.

Previously I had:

redis = require('redis'),
redisPub = redis.createClient(),
redisSub = redis.createClient(),
redisClient = redis.createClient(),
RedisStore = require('connect-redis')(express),
sessionStore = new RedisStore({
  client: redisClient
}),
socketRedisStore = require('socket.io/lib/stores/redis'),
socketRedis = require('socket.io/node_modules/redis'),

...

io.configure(function() {
  io.set('log level', 1);
  io.set('store', new socketRedisStore({
    redisPub: redisPub,
    redisSub: redisSub,
    redisClient: redisClient
  }));
  io.set('authorization', function(data, accept) {

...

Into this:

redis = require('redis'),
redisPub = redis.createClient(),
redisSub = redis.createClient(null, null, {detect_buffers: true}),
redisClient = redis.createClient(),
RedisStore = require('connect-redis')(express),
sessionStore = new RedisStore({
  client: redisClient
}),
socketRedisStore = require('socket.io/lib/stores/redis'),
socketRedis = require('socket.io/node_modules/redis'),

...

io.configure(function() {
  io.set('log level', 1);
  io.set('store', new socketRedisStore({
    redis: redis,
    redisPub: redisPub,
    redisSub: redisSub,
    redisClient: redisClient
  }));
  io.set('authorization', function(data, accept) {

...

Note the inclusion of the options in the redisSub, to detect buffers, and then the injection of the base redis object into the socket.io store configuration.

Upvotes: 1

thomas
thomas

Reputation: 2578

Did you install MsgPack? After I used

npm install msgpack

Socket.IO would show me the exact error you posted.

I uninstalled MsgPack via

npm uninstall msgpack

and everything worked just fine again. This is not the solution to the problem, but it is a workaround to get your system back running.

Upvotes: 2

Related Questions