Socket.io失败并出现内部错误

时间:2012-12-21 02:16:42

标签: node.js redis socket.io

我最近运行了npm install,它更新了我的所有软件包。出于某种原因,这破坏了我的网络服务器(每当我尝试加载页面时,它只会加载部分方式并因此错误而死亡)。我尝试回滚socket.io,redis和nodetime的版本,这些是堆栈跟踪中显示的软件包,但是我没有运气让web服务器再次运行。救命?我在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)

2 个答案:

答案 0 :(得分:2)

你安装了MsgPack吗? 我用完之后

npm install msgpack

Socket.IO会告诉我你发布的确切错误。

我通过

卸载了MsgPack
npm uninstall msgpack

一切都运转得很好。 这不是问题的解决方案,但它是让您的系统重新运行的解决方法。

答案 1 :(得分:1)

不幸的是,我的项目中需要MsgPack,因此我无法使用此处列出的答案。

相反,我找到了这个页面: https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO

这让我对这些代码进行了更改。

以前我曾经:

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

...

进入这个:

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

...

请注意,在redisSub中包含选项,以检测缓冲区,然后将基本redis对象注入socket.io存储配置。