Closed mseld closed 5 years ago
I would suggest using process control system, like Supervisor, which will ensure your process / node is up & running. Once socket is unintentionally unbinded/closed, Supervisor restarts it.
Hello @ritmas
i'm already use pm2 as process manager
but i need to keep service a live even connection is dropped and try to establish connection again
because i need to fail over to another provider after number of trails
I've tested pm2
recently, as it was new for me, but I couldn't reproduce the case once connection is dropped from server side and client wouldn't able to reconnect - it always rebind successfully, at least in my case. @mseld could you share exact error code / test scenario which fails client to reconnect/rebind?
My test case: initiated random session.close();
from server side, but client is keep rebinding:
PM2 > App [client:0] starting in -fork mode-
PM2 > App [client:0] online
client > client: connected
client > client: binded
client > client: socket closed
PM2 > App [client:0] exited with code [0] via signal [SIGINT]
PM2 > App [client:0] starting in -fork mode-
PM2 > App [client:0] online
client > client: connected
client > client: binded
Hello @ritmas there's no problem in pm2 to do like this functionality that you mention in previous comment. What i need it different , i need to implement fail-over strategy when smpp client can't connect to provider after number of trails it should use different connection.
Have you tried the following?
var smpp = require('smpp'),
// used '127.0.0.2' intentionally so to mimic cannot-connect case
session = smpp.connect('127.0.0.2', 2775);
// info: https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback
session.socket.setTimeout(1000);
session.socket.on('timeout', function() {
console.log('socket timeout');
session.destroy();
});
@mseld it's been more than 2 months from last response, did you find it useful? did you solved your problem?
@juliangut Yes i find the way to solve this case using below code
session.socket.on('close', function(had_err) {
setTimeout(() => {
session.connect();
session.resume();
}, 1000);
});
Tnaks for the aswer @mseld , closing this issue
@juliangut @mseld Thank you guys for the solution, I was looking for this,
But I am getting this warning in the terminal:
(node:37152) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 connect listeners added to [Socket]. Use emitter.setMaxListeners() to increase limit
I am asking you if you can add new feature to allow session reconnect considering is session unbind/closed or even tcp socket closed