mirror of https://github.com/calzoneman/sync.git
Adjust some socket.io settings (#780)
This commit is contained in:
parent
1f28c0b87d
commit
f6a58d00b2
|
@ -2,7 +2,7 @@
|
||||||
"author": "Calvin Montgomery",
|
"author": "Calvin Montgomery",
|
||||||
"name": "CyTube",
|
"name": "CyTube",
|
||||||
"description": "Online media synchronizer and chat",
|
"description": "Online media synchronizer and chat",
|
||||||
"version": "3.59.1",
|
"version": "3.60.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "http://github.com/calzoneman/sync"
|
"url": "http://github.com/calzoneman/sync"
|
||||||
},
|
},
|
||||||
|
|
|
@ -289,8 +289,37 @@ class IOServer {
|
||||||
throw new Error('Cannot bind: socket.io has not been initialized yet');
|
throw new Error('Cannot bind: socket.io has not been initialized yet');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const engineOpts = {
|
||||||
|
/*
|
||||||
|
* Set ping timeout to 2 minutes to avoid spurious reconnects
|
||||||
|
* during transient network issues. The default of 5 minutes
|
||||||
|
* is too aggressive.
|
||||||
|
*
|
||||||
|
* https://github.com/calzoneman/sync/issues/780
|
||||||
|
*/
|
||||||
|
pingTimeout: 120000,
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Per `ws` docs: "Note that Node.js has a variety of issues with
|
||||||
|
* high-performance compression, where increased concurrency,
|
||||||
|
* especially on Linux, can lead to catastrophic memory
|
||||||
|
* fragmentation and slow performance."
|
||||||
|
*
|
||||||
|
* CyTube's frames are ordinarily quite small, so there's not much
|
||||||
|
* point in compressing them.
|
||||||
|
*/
|
||||||
|
perMessageDeflate: false,
|
||||||
|
httpCompression: false,
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Default is 10MB.
|
||||||
|
* Even 1MiB seems like a generous limit...
|
||||||
|
*/
|
||||||
|
maxHttpBufferSize: 1 << 20
|
||||||
|
};
|
||||||
|
|
||||||
servers.forEach(server => {
|
servers.forEach(server => {
|
||||||
this.io.attach(server);
|
this.io.attach(server, engineOpts);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -375,6 +404,10 @@ const promSocketDisconnect = new Counter({
|
||||||
name: 'cytube_sockets_disconnects_total',
|
name: 'cytube_sockets_disconnects_total',
|
||||||
help: 'Counter for number of connections disconnected.'
|
help: 'Counter for number of connections disconnected.'
|
||||||
});
|
});
|
||||||
|
const promSocketReconnect = new Counter({
|
||||||
|
name: 'cytube_sockets_reconnects_total',
|
||||||
|
help: 'Counter for number of reconnects detected.'
|
||||||
|
});
|
||||||
function emitMetrics(sock) {
|
function emitMetrics(sock) {
|
||||||
try {
|
try {
|
||||||
let closed = false;
|
let closed = false;
|
||||||
|
@ -406,6 +439,15 @@ function emitMetrics(sock) {
|
||||||
sock.context.ipAddress, error.stack);
|
sock.context.ipAddress, error.stack);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
sock.once('reportReconnect', () => {
|
||||||
|
try {
|
||||||
|
promSocketReconnect.inc(1, new Date());
|
||||||
|
} catch (error) {
|
||||||
|
LOGGER.error('Error emitting reconnect metrics for socket (ip=%s): %s',
|
||||||
|
sock.context.ipAddress, error.stack);
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LOGGER.error('Error emitting metrics for socket (ip=%s): %s',
|
LOGGER.error('Error emitting metrics for socket (ip=%s): %s',
|
||||||
sock.context.ipAddress, error.stack);
|
sock.context.ipAddress, error.stack);
|
||||||
|
|
|
@ -35,6 +35,10 @@ Callbacks = {
|
||||||
scrollChat();
|
scrollChat();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
reconnect: function () {
|
||||||
|
socket.emit("reportReconnect");
|
||||||
|
},
|
||||||
|
|
||||||
// Socket.IO error callback
|
// Socket.IO error callback
|
||||||
error: function (msg) {
|
error: function (msg) {
|
||||||
window.SOCKET_ERROR_REASON = msg;
|
window.SOCKET_ERROR_REASON = msg;
|
||||||
|
|
Loading…
Reference in New Issue