Note that there are some explanatory texts on larger screens.

plurals
  1. POIssues with long polling XMLHttpRequests and intermittent network connections
    primarykey
    data
    text
    <p>I've implemented a long polling connection to allow me to do server-side push (comet) using a Tomcat web server and standard javascript on the frontend. To keep the connection going, I have a simple keep-alive loop that initiates a new request as soon as the last one completes/fails.</p> <p>The vast majority of the time, this connection works perfectly fine and keeps alive as I expect. But, I've noticed that when a user's internet connection drops out (e.g. they disconnect from a VPN, unplug their ethernet, etc.) AND I have a pending XMLHttpRequest out to the server, I get no indication of failure. Because of this, the connection dies silently, and I can't know that it's happened unless I constantly send requests to the server to test the connection (which seems to defeat the purpose of using long polling).</p> <p>Here's the request object that I see in Chrome when it dies this silent death:</p> <pre><code>request: XMLHttpRequest onabort: function () onerror: function () onload: null onloadend: null onloadstart: null onprogress: null onreadystatechange: function () readyState: 1 response: "" responseText: "" responseType: "" responseXML: null status: [Exception: DOMException] statusText: [Exception: DOMException] upload: XMLHttpRequestUpload withCredentials: false </code></pre> <p>I have the three listeners (onabort, onerror, onreadystatechange) setup to alert a message if they ever get fired, but I get nothing whenever I take my connection to the server down. Here's how I'm forming the request:</p> <pre><code>var request = new XMLHttpRequest(); //url is just the url to my servlet to handle this request.open("GET", url, true); //handlestatechange is just my standard handling code //that I've put an alert at the top of request.onreadystatechange = handleStateChange; request.onerror = function() { alert("We encountered an error"); } request.onabort = function() { alert("I've had an abortion"); } request.send(null); </code></pre> <p>It seems like this would be a pretty standard situation, but I've not seen any conversations on how to allow a long polling connection to recover from this sort of disconnection.</p> <p>Am I doing something wrong? Is there some other more standard approach to doing long polling/comet that circumvents this issue?</p> <p>Any help with this would be appreciated, Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload