socket.io-redis-adapter: uncaught error: 348 trailing bytes
I am using socket.io-emitter to broadcast an event to a set of channels with a for loop:
In the file, I have:
// in the file
var io = require('socket.io-emitter')({
host: 'localhost',
port: 6379
});
module.exports = {
exampleFunction: function(req, res, next) {
var channels = req.param('channels'),
data = req.param('data');
for (var i=0; i<channels.length; i++) {
io.to(channels[i]).emit('example event', data)
}
}
}
In app.js, I have socket.io-redis:
io.adapter(socketio_redis({
host: 'localhost',
port: 6379,
pubClient: redis.createClient(6379, '127.0.0.1'),
subClient: redis.createClient(6379, '127.0.0.1')
}))
When I try to run exampleFunction, I get the following uncaught error in my console:
Error: 348 trailing bytes
at Object.decode (C:\Users\Zachary\Documents\GitHub\thegraduate_backend\node
_modules\socket.io-redis\node_modules\msgpack-js\msgpack.js:200:47)
at Redis.onmessage (C:\Users\Zachary\Documents\GitHub\thegraduate_backend\no
de_modules\socket.io-redis\index.js:93:24)
at RedisClient.EventEmitter.emit (events.js:106:17)
at RedisClient.return_reply (C:\Users\Zachary\Documents\GitHub\thegraduate_b
ackend\node_modules\redis\index.js:672:22)
at ReplyParser.<anonymous> (C:\Users\Zachary\Documents\GitHub\thegraduate_ba
ckend\node_modules\redis\index.js:309:14)
at ReplyParser.EventEmitter.emit (events.js:95:17)
at ReplyParser.send_reply (C:\Users\Zachary\Documents\GitHub\thegraduate_bac
kend\node_modules\redis\lib\parser\javascript.js:300:10)
at ReplyParser.execute (C:\Users\Zachary\Documents\GitHub\thegraduate_backen
d\node_modules\redis\lib\parser\javascript.js:211:22)
at RedisClient.on_data (C:\Users\Zachary\Documents\GitHub\thegraduate_backen
d\node_modules\redis\index.js:534:27)
at Socket.<anonymous> (C:\Users\Zachary\Documents\GitHub\thegraduate_backend
\node_modules\redis\index.js:91:14)
When I change data to be something smaller, like:
var data = { testing: true }
I get the same error, but to a smaller number of trailing bytes. e.g. 95 trailing bytes.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 1
- Comments: 33
Commits related to this issue
- set {return_buffers: true} on socket.io redis clients see: https://github.com/Automattic/socket.io-redis/issues/17 — committed to SizzlingStats/sizzlingstats.com by dy-dx 10 years ago
- https://github.com/Automattic/socket.io-redis/issues/17 — committed to vodolaz095/hunt by vodolaz095 10 years ago
- temporary fix for issues in npmjs.org/package/redis module conflicting with socket.io https://github.com/socketio/socket.io-redis/issues/17 sometimes they are back — committed to vodolaz095/hunt by vodolaz095 9 years ago
Hi ! Actually the bug exists if you use the same redis client in socket.io-redis and in a “classic” usage. Just create two more redisClient to pub and sub.
I was able to install the v5 version of msgpack-js-v5, npm i msgpack-js-v5 --save
then change the requires statement in node_modules/socket.io-redis/index.js (around line 8) from var msgpack = require(‘msgpack-js’); to var msgpack = require(‘msgpack-js-v5’);
and that worked in my setup.