1

我最近运行了 npm install,它更新了我所有的包。出于某种原因,这破坏了我的网络服务器(每当我尝试加载页面时,它只会加载一部分并死于此错误)。我尝试回滚版本的 socket.io、redis 和 nodetime,它们是出现在堆栈跟踪中的包,但是我没有运气让网络服务器再次工作。帮助?我在 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)
4

2 回答 2

2

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

npm install msgpack

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

我通过卸载 MsgPack

npm uninstall msgpack

一切都恢复正常了。这不是问题的解决方案,但它是让您的系统重新运行的解决方法。

于 2013-10-28T09:18:03.670 回答
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 存储配置中。

于 2013-12-20T18:47:18.013 回答