Comments (21)
You can access to an adapter instance like:
io.of('/').adapter.on('error', funtion(err) {});
from socket.io-redis-adapter.
Putting a listener on adapter.prototype actually works... That's far from intuitive...
Example:
var adapter = socketIORedis();
adapter.prototype.on('error',function(err) {
debug('adapter error: ',err);
});
io.adapter(adapter);
from socket.io-redis-adapter.
The adapter inherits from Emitter
, so simply attach an error
listener on the emitter instance.
from socket.io-redis-adapter.
@guille, could you please advise on valid syntax for 'error' event. I can't find any working solution.
from socket.io-redis-adapter.
Attach it on the adapter instance? On the object you pass to io.adapter
from socket.io-redis-adapter.
Guillermo, thanks for your feedback, unfortunately it doesn't work with v. 0.1.3. Here is my code:
var redis = require('socket.io-redis');
var redisAdapter = redis({ host: 'abc', port: 12345 });
redisAdapter.on('error', function(err) {});
io.adapter(redisAdapter);
There is no 'on' method in redisAdapter object. Here is error:
redisAdapter.on('error', function(err) {});
^
TypeError: Object function Redis(nsp){
Adapter.call(this, nsp);
var self = this;
sub.psubscribe(prefix + '#*', function(err){
if (err) self.emit('error', err);
});
sub.on('pmessage', this.onmessage.bind(this));
} has no method 'on'
from socket.io-redis-adapter.
Try redisAdapter.prototype.on('error', function(err) {});
that worked for me. But it feels a bit strange to edit the prototype...
from socket.io-redis-adapter.
It's not working for me. When I kill Redis server, whole app crashes:
events.js:72
throw er; // Unhandled 'error' event
from socket.io-redis-adapter.
I'm having the same issue, please reopen.
The emit in the psubscribe callback is throwing an error, which can't be catched in a good way.
https://github.com/Automattic/socket.io-redis/blob/master/index.js#L73
I did add an error event handler:
var adapter = io.adapter(socketIORedis({ key: 'socket.io-redis-experiment',
pubClient: pub,
subClient: sub}));
adapter.on('error',function(err) {
debug('adapter error: ',err);
});
from socket.io-redis-adapter.
Adding a error listener on self
, just before sub.psubscribe
solves the unhandled error...
self.on('error',function(err) {
console.log("socket.io-redis inside error handler: ",err);
});
Maybe the right instance reference isn't returned from the require?
from socket.io-redis-adapter.
I think I understand the problem, require('socket.io-redis')
returns a "class" and every namespace creates it's own adapter instance from this.
from socket.io-redis-adapter.
I tried the solution suggested by @peteruithoven but no luck... The error is still thrown causing a crash of the application. Is there some news about this issue?
from socket.io-redis-adapter.
@emidiocroci, did you also try adding error listeners to the pub and sub clients?
from socket.io-redis-adapter.
Not... How can I do it?
Il 23/ott/2014 23:20 "Peter Uithoven" [email protected] ha scritto:
@emidiocroci https://github.com/emidiocroci, did you also try adding
error listeners to the pub and sub clients?—
Reply to this email directly or view it on GitHub
#21 (comment)
.
from socket.io-redis-adapter.
Small example:
io.adapter(initRedisAdapter(config.REDIS_PORT,config.REDIS_HOST));
function initRedisAdapter(port,host) {
var pub = redis.createClient(port,host,{detect_buffers: true});
pub.on('error',onRedisError);
var sub = redis.createClient(port,host,{detect_buffers: true});
sub.on('error',onRedisError);
var redisAdapter = RedisAdapter({pubClient: pub,
subClient: sub,
key: 'your key'});
redisAdapter.prototype.on('error',onRedisError);
function onRedisError(err){
debug("Redis error: ",err);
}
return redisAdapter;
}
from socket.io-redis-adapter.
Thanks @peteruithoven, worked like a charm!
Where did you find those info about redis adapter initialization?
from socket.io-redis-adapter.
Source code of socket.io ;)
from socket.io-redis-adapter.
@nkzawa 3x! You are right. Using radis adapter API also need to add of(namespace)!!!
from socket.io-redis-adapter.
io.of('/').adapter.on('error', funtion(err) {});
this didn't work for me,
only adding the handler to the prototype as @peteruithoven suggesed worked for me
from socket.io-redis-adapter.
Same. Using version 5.2.0
and only catching errors on the pubClient and subClient still caused my app to crash.
Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1117:14)
Adding:
adapter.prototype.on("error", err => logger.error("PROTOTYPE", { err }));
will prevent the app from crashing:
2018-10-25T10:17:56.307Z error: PROTOTYPE [err: Error: connect ECONNREFUSED 127.0.0.1:6379] [severity: ERROR]
2018-10-25T10:17:56.308Z error: PROTOTYPE [err: Error: connect ECONNREFUSED 127.0.0.1:6379] [severity: ERROR]
2018-10-25T10:17:56.467Z error: PROTOTYPE [err: MaxRetriesPerRequestError: Reached the max retries per request limit (which is 3). Refer to "maxRetriesPerRequest" option for details.] [severity: ERROR]
However, it will not retry forever to establish the Redis connection and will stay zombie.
from socket.io-redis-adapter.
Same. Using version
5.2.0
and only catching errors on the pubClient and subClient still caused my app to crash.Error: connect ECONNREFUSED 127.0.0.1:6379 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1117:14)
Adding:
adapter.prototype.on("error", err => logger.error("PROTOTYPE", { err }));
will prevent the app from crashing:
2018-10-25T10:17:56.307Z error: PROTOTYPE [err: Error: connect ECONNREFUSED 127.0.0.1:6379] [severity: ERROR] 2018-10-25T10:17:56.308Z error: PROTOTYPE [err: Error: connect ECONNREFUSED 127.0.0.1:6379] [severity: ERROR] 2018-10-25T10:17:56.467Z error: PROTOTYPE [err: MaxRetriesPerRequestError: Reached the max retries per request limit (which is 3). Refer to "maxRetriesPerRequest" option for details.] [severity: ERROR]
However, it will not retry forever to establish the Redis connection and will stay zombie.
To keep the reconnection protocol, instantiate the redis client separately from the adapter. Implement reconnection protocols on this redis client and let it reconnect. Let adapter.prototype.on catch the error handle even redundantly. That way, you'll get the best of both worlds.
from socket.io-redis-adapter.
Related Issues (20)
- Does this work with ioredis-mock? HOT 1
- redisClient.send_command is not a function HOT 1
- UnhandledPromiseRejection when trying to add a RedisAdapter to socketIO
- Consult about a logic problem in the code
- Retrieving number of connected sockets using `fetchSockets` without getting all socket information HOT 5
- Make subscription client optional HOT 1
- Proper way to use this adapter with ioredis HOT 2
- Feature request: limit nodes hit by "serverSideEmit" and "fetchSockets" in sharded adapter
- Error on websocket multi instance using redis-adapter HOT 1
- This.io.sockets.adapter.pubClient.isReady becomes false and is never ready again HOT 2
- Error: 23984 trailing bytes HOT 5
- dynamic subscription mode breaks remote socket.emit() HOT 3
- [email protected]: timeout reached while waiting for fetchSockets response
- MaxListenersExceededWarning due to SSUBSCRIBE/SUNSUBSCRIBE memory leak HOT 2
- the below error occurs when the user disconnect from the socket HOT 1
- the below error occurs when the user disconnect from the socket HOT 1
- Socket.io adapter HOT 1
- TypeError with @socket.io/redis-adapter on Node.js v18.15.0 HOT 5
- Lot of "ignoring unknown request" in Debug HOT 5
- Unnecessary psubscribe Operations in Namespaces Without Local Clients Increasing Redis Pub/Sub Channels HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from socket.io-redis-adapter.