jpillora / xdomain

A pure JavaScript CORS alternative
https://jpillora.com/xdomain/
3.12k stars 270 forks source link

Socket timeout.. rarely and randomly. #77

Closed peoplesoft closed 10 years ago

peoplesoft commented 10 years ago

Hi, So the connectivity b/w my master and slave using your script works most of the time but, every now and then (and rarely), it stops working. The console window shows, "Timeout waiting on iframe socket".

here's what I get with debug=true on failure (on chrome):

xdomain (http://127.0.0.1:9000): adding slave: http://myslave.com xdomain.js:922 xdomain (http://127.0.0.1:9000): proxying request to slave: 'http://myslave.com' xdomain.js:922 xdomain (http://127.0.0.1:9000): creating iframe xdomain-704c63c9 xdomain.js:922 xdomain (http://127.0.0.1:9000): new socket: xdomain-d11e00cf xdomain.js:922 xdomain (http://127.0.0.1:9000): proxying request to slave: 'http://myslave.com' xdomain.js:922 xdomain (http://127.0.0.1:9000): new socket: xdomain-adadfd31 xdomain.js:922 xdomain (http://127.0.0.1:9000): Timeout waiting on iframe socket xdomain.js:922 xdomain (http://127.0.0.1:9000): Timeout waiting on iframe socket

Appreciate if you could provide some clues on how to fix this.

jpillora commented 10 years ago

You might have a slow slave, you can increase the timeout from 15sec, to 20, or 30?

xdomain.timeout = 20*1000;

It will also timeout if the slave fails to respond with the proxy.html and the only way to detect this is through timeouts

As an hacky fix, you could listen for the timeout message and reload the page:

xdomain.warn = function(message) {
  if(/Timeout/.test(message)) location.href = location.href;
};
peoplesoft commented 10 years ago

Thank-you!

dmarlow commented 10 years ago

How can I go about troubleshooting it further? I get the timeout, but I can see my proxy.html is loading successfully.