Переглянути джерело

Set default BOSH `wait` time to 59

to avoid timing conflicts with the webserver
JC Brand 7 роки тому
батько
коміт
964b10dc33
2 змінених файлів з 14 додано та 3 видалено
  1. 7 1
      docs/source/setup.rst
  2. 7 2
      src/converse-core.js

+ 7 - 1
docs/source/setup.rst

@@ -202,7 +202,10 @@ Apache
         Line Number 6, Column 3: bosh-anon:6:3
         Line Number 6, Column 3: bosh-anon:6:3
         Also ERROR: request id 12.2 error 504 happened
         Also ERROR: request id 12.2 error 504 happened
 
 
-    Then it might be because your webserver and BOSH proxy have the same timeout
+    Then your BOSH proxy is returning an HTML error page (for a 504 error in
+    the above example).
+
+    This might be because your webserver and BOSH proxy have the same timeout
     for BOSH requests. Because the webserver receives the request slightly earlier, 
     for BOSH requests. Because the webserver receives the request slightly earlier, 
     it gives up a few microseconds before the XMPP server’s empty result and thus returns a
     it gives up a few microseconds before the XMPP server’s empty result and thus returns a
     504 error page containing HTML to browser, which then gets parsed as if its
     504 error page containing HTML to browser, which then gets parsed as if its
@@ -211,6 +214,9 @@ Apache
     To fix this, make sure that the webserver's timeout is slightly higher.
     To fix this, make sure that the webserver's timeout is slightly higher.
     In Nginx you can do this by adding ``proxy_read_timeout 61;``;
     In Nginx you can do this by adding ``proxy_read_timeout 61;``;
 
 
+    From Converse 4.0.0 onwards the default ``wait`` time is set to 59 seconds, to avoid
+    this problem.
+
 
 
 .. _`session-support`:
 .. _`session-support`:
 
 

+ 7 - 2
src/converse-core.js

@@ -98,6 +98,11 @@
         'converse-vcard'
         'converse-vcard'
     ];
     ];
 
 
+    // Setting wait to 59 instead of 60 to avoid timing conflicts with the
+    // webserver, which is often also set to 60 and might therefore sometimes
+    // return a 504 error page instead of passing through to the BOSH proxy.
+    const BOSH_WAIT = 59;
+
     // Make converse pluggable
     // Make converse pluggable
     pluggable.enable(_converse, '_converse', 'pluggable');
     pluggable.enable(_converse, '_converse', 'pluggable');
 
 
@@ -1025,7 +1030,7 @@
                 if (!this.connection.reconnecting) {
                 if (!this.connection.reconnecting) {
                     this.connection.reset();
                     this.connection.reset();
                 }
                 }
-                this.connection.connect(this.jid.toLowerCase(), null, this.onConnectStatusChanged);
+                this.connection.connect(this.jid.toLowerCase(), null, this.onConnectStatusChanged, BOSH_WAIT);
             } else if (this.authentication === _converse.LOGIN) {
             } else if (this.authentication === _converse.LOGIN) {
                 const password = _.isNil(credentials) ? (_converse.connection.pass || this.password) : credentials.password;
                 const password = _.isNil(credentials) ? (_converse.connection.pass || this.password) : credentials.password;
                 if (!password) {
                 if (!password) {
@@ -1046,7 +1051,7 @@
                 if (!this.connection.reconnecting) {
                 if (!this.connection.reconnecting) {
                     this.connection.reset();
                     this.connection.reset();
                 }
                 }
-                this.connection.connect(this.jid, password, this.onConnectStatusChanged);
+                this.connection.connect(this.jid, password, this.onConnectStatusChanged, BOSH_WAIT);
             }
             }
         };
         };