Closed jamesleegit closed 2 years ago
client.on('connect', function(connection) {
let isClose = false;
const heartbeat = () => {
if (isClose) {
return;
}
connection.ping("#ping");
setTimeout(()=>heartbeat(), 3000);
}
heartbeat();
connection.on('error', function(error) {
isClose = true;
});
connection.on('close', function() {
isClose = true;
setTimeout(function(){
createConnection();
}, 3000);
});
솔루션
네 감사합니다. 해당 부분은 수정해두도록 하겠습니다.
이런소스는 좋지않습니다. connection이 끊어졌을 때도 계속 타이머 돌면서 연결끊킨 connection에 ping 을 보내기 때문입니다. connection이 정상상태가 아니라면 저 루프에서 빠져나오는 release 로직까지 짜두어야합니다.