Merge pull request #2881 from overleaf/jpa-socket-io-retry-handshake

[misc] socket.io: retry the initial connection attempt

GitOrigin-RevId: e7f7e8eb233015f41b2b8c67e46c4661b8fad3c9
This commit is contained in:
Chrystal Maria Griffiths 2020-06-05 11:15:16 +01:00 committed by Copybot
parent d536e57ed8
commit 50585a22b3
3 changed files with 10 additions and 0 deletions

View file

@ -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').

View file

@ -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,

View file

@ -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/)) {