Skip to content

Node.js based forum software built for the modern web

fixed issue where socket.io would no longer reconnect perpetually, new behaviour waits 10x the reconnect delay, and then starts over. Also upped the reconnection delay default to 1.5s.

Julian Lam2a80140e704b
diff --git a/public/src/app.js b/public/src/app.js
index 53e43e86fc..d1f6ab93bc 100644
--- a/public/src/app.js
+++ b/public/src/app.js
@@ -17,12 +17,12 @@ app.cacheBuster = null;
function socketIOConnect() {
var ioParams = {
reconnectionAttempts: config.maxReconnectionAttempts,
- reconnectionDelay : config.reconnectionDelay,
+ reconnectionDelay: config.reconnectionDelay,
transports: config.socketioTransports,
path: config.relative_path + '/socket.io'
};
- socket = io.connect(config.websocketAddress, ioParams);
+ socket = io(config.websocketAddress, ioParams);
reconnecting = false;
socket.on('event:connect', function () {
@@ -41,11 +41,6 @@ app.cacheBuster = null;
});
socket.on('reconnecting', function (attempt) {
- if(attempt === parseInt(config.maxReconnectionAttempts, 10)) {
- socket.io.attempts = 0;
- return;
- }
-
reconnecting = true;
var reconnectEl = $('#reconnect');
@@ -74,6 +69,11 @@ app.cacheBuster = null;
socket.on('event:alert', function(data) {
app.alert(data);
});
+
+ socket.on('reconnect_failed', function() {
+ // Wait ten times the reconnection delay and then start over
+ setTimeout(socket.connect.bind(socket), parseInt(config.reconnectionDelay, 10) * 10);
+ });
}
function onSocketConnect(data) {
diff --git a/src/controllers/api.js b/src/controllers/api.js
index c98fd79e0c..8be2211ca1 100644
--- a/src/controllers/api.js
+++ b/src/controllers/api.js
@@ -51,7 +51,7 @@ apiController.getConfig = function(req, res, next) {
config.disableSocialButtons = parseInt(meta.config.disableSocialButtons, 10) === 1;
config.disableChat = parseInt(meta.config.disableChat, 10) === 1;
config.maxReconnectionAttempts = meta.config.maxReconnectionAttempts || 5;
- config.reconnectionDelay = meta.config.reconnectionDelay || 200;
+ config.reconnectionDelay = meta.config.reconnectionDelay || 1500;
config.tagsPerTopic = meta.config.tagsPerTopic || 5;
config.minimumTagLength = meta.config.minimumTagLength || 3;
config.maximumTagLength = meta.config.maximumTagLength || 15;
diff --git a/src/views/admin/settings/sockets.tpl b/src/views/admin/settings/sockets.tpl
index ab24ab2970..94ef41bf56 100644
--- a/src/views/admin/settings/sockets.tpl
+++ b/src/views/admin/settings/sockets.tpl
@@ -6,11 +6,11 @@
<form>
<div class="form-group">
<label for="maxReconnectionAttempts">Max Reconnection Attempts</label>
- <input class="form-control" id="maxReconnectionAttempts" type="text" value="5" data-field="maxReconnectionAttempts" />
+ <input class="form-control" id="maxReconnectionAttempts" type="text" value="5" placeholder="Default: 5" data-field="maxReconnectionAttempts" />
</div>
<div class="form-group">
<label for="reconnectionDelay">Reconnection Delay</label>
- <input class="form-control" id="reconnectionDelay" type="text" value="200" data-field="reconnectionDelay" />
+ <input class="form-control" id="reconnectionDelay" type="text" value="1500" placeholder="Default: 1500" data-field="reconnectionDelay" />
</div>
</form>
</div>