diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug index 5177c0afe2..81f2b61e08 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -179,6 +179,7 @@ block content //- enable doc hash checking for all projects //- used in public/js/libs/sharejs.js window.useShareJsHash = true + window.wsRetryHandshake = #{settings.wsRetryHandshake} - if (settings.overleaf != null) script(type='text/javascript'). diff --git a/services/web/config/settings.defaults.coffee b/services/web/config/settings.defaults.coffee index afa3e907b1..ec954eaec5 100644 --- a/services/web/config/settings.defaults.coffee +++ b/services/web/config/settings.defaults.coffee @@ -211,6 +211,7 @@ module.exports = settings = wsUrlBeta: process.env['WEBSOCKET_URL_BETA'] wsUrlV2Percentage: parseInt(process.env['WEBSOCKET_URL_V2_PERCENTAGE'] || '0', 10) + wsRetryHandshake: parseInt(process.env['WEBSOCKET_RETRY_HANDSHAKE'] || '5', 10) # cookie domain # use full domain for cookies to only be accessible from that domain, diff --git a/services/web/frontend/js/ide/connection/ConnectionManager.js b/services/web/frontend/js/ide/connection/ConnectionManager.js index abe1af2279..afdf2ab597 100644 --- a/services/web/frontend/js/ide/connection/ConnectionManager.js +++ b/services/web/frontend/js/ide/connection/ConnectionManager.js @@ -11,6 +11,7 @@ /* global io */ import SocketIoShim from './SocketIoShim' + let ConnectionManager const ONEHOUR = 1000 * 60 * 60 @@ -136,7 +137,14 @@ export default (ConnectionManager = (function() { // handle network-level websocket errors (e.g. failed dns lookups) + let connectionAttempt = 1 let connectionErrorHandler = err => { + if ( + window.wsRetryHandshake && + connectionAttempt++ < window.wsRetryHandshake + ) { + return setTimeout(() => this.ide.socket.socket.connect(), 100) + } this.updateConnectionManagerState('error') sl_console.log('socket.io error', err) if (this.wsUrl && !window.location.href.match(/ws=fallback/)) {