From 9c923be5f05f433a1bd3d050f6cd83e3eb5d0ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 12 Apr 2018 13:19:02 +0200 Subject: [PATCH] Better solution for the Tornado 5 + SockJS + haproxy issue Looks like Nagle's algorithm was the cause. Adding option http-no-delay to haproxy.cfg solves the problem without modification of the timeout, however that is not an option for the thousands of instances already deployed in the field. So instead we add 300ms to the roundtrip based connection timeout, that should hopefully get around any Nagle-induced delays (usually between 40 and 200ms according to various sites on the net). --- src/octoprint/static/js/lib/sockjs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/octoprint/static/js/lib/sockjs.js b/src/octoprint/static/js/lib/sockjs.js index 52431ec9e..dff4b42c7 100644 --- a/src/octoprint/static/js/lib/sockjs.js +++ b/src/octoprint/static/js/lib/sockjs.js @@ -817,8 +817,8 @@ SockJS.prototype._connect = function() { } } - // calculate timeout based on RTO and round trips. Default to 5s - var timeoutMs = (this._rto * Transport.roundTrips * 2) || 5000; + // calculate timeout based on RTO and round trips, compensate for potential nagle. Default to 5s. + var timeoutMs = (this._rto * Transport.roundTrips + 300) || 5000; this._transportTimeoutId = setTimeout(this._transportTimeout.bind(this), timeoutMs); debug('using timeout', timeoutMs);