merge: fix-ack-dead-socket into master

This commit is contained in:
2026-07-06 15:30:49 +00:00
+17 -3
View File
@@ -41,6 +41,10 @@ class Appv2 {
return 10; return 10;
} }
get ackTimeoutMs() {
return Number(process.env.ACK_TIMEOUT_MS || 1500);
}
_takeIO() { _takeIO() {
this.app = express(); this.app = express();
this.server = http.createServer(this.app); this.server = http.createServer(this.app);
@@ -64,13 +68,17 @@ class Appv2 {
console.log('publish to ' + room + ' data:'); console.log('publish to ' + room + ' data:');
console.log(req.body); console.log(req.body);
const userId = room.split("_")[0]; const userId = room.split("_")[0];
const connection = this.connections[userId];
if (typeof this.connections[userId] === 'undefined') { if (typeof connection === 'undefined' || !connection.connected) {
if (typeof connection !== 'undefined' && !connection.connected) {
delete this.connections[userId];
}
th.addToQueue(userId, req.body); th.addToQueue(userId, req.body);
this.postResponse(res, 404); this.postResponse(res, 404);
return; return;
} }
this.connections[userId].timeout(100).emit('data', req.body, (err, response)=> { connection.timeout(this.ackTimeoutMs).emit('data', req.body, (err, response)=> {
let success = true; let success = true;
console.log(response); console.log(response);
if(typeof response !== 'undefined') { if(typeof response !== 'undefined') {
@@ -99,9 +107,15 @@ class Appv2 {
this.connections[userId] = socket; this.connections[userId] = socket;
this.tryResolveQueueStorage(userId, room).then(r => console.log(r)); this.tryResolveQueueStorage(userId, room).then(r => console.log(r));
console.log('user ' + socket.id + ' joined to room ' + room); console.log('user ' + socket.id + ' joined to room ' + room);
socket.on('disconnect', () => {
if (this.connections[userId] === socket) {
delete this.connections[userId];
}
console.log('user ' + socket.id + ' disconnected');
});
return;
} }
socket.on('disconnect', () => { socket.on('disconnect', () => {
const room = socket.handshake.query.id;
console.log('user ' + socket.id + ' disconnected'); console.log('user ' + socket.id + ' disconnected');
}); });
} }