Failed to load resource: net::ERR_NETWORK_IO_SUSPENDED

JavascriptBrowser

Javascript Problem Overview


I searched Stack Overflow and Google for the specific error message in the title, but I did not find it (in the context of JavaScript coding, not browser settings). On my site, there are five functions that are called every 10 seconds. These functions do things such as:

  1. Check the user's inbox for new emails
  2. Check the user's account for new instant messages
  3. etc.

However, if the user is logged in, but is INACTIVE (does not use the mouse or press any keys) for about 15 minutes, I get the following error message when I "Inspect Element" with Chrome:

Failed to load resource: net::ERR_NETWORK_IO_SUSPENDED // (x 5)
Uncaught Type Error: Cannot read property 'combinedfiletimeinput' of undefined //one of my previously defined form values is now not defined

At this point, the user's new email count, new IM count, etc. go blank (whereas they were integers before). All the user has to do is refresh the page or go to another page to reconnect, so it's not a huge deal.

My hack solution is to use a JavaScript timer to automatically logout the user if there is not any of the following events in a 15 minute period:

  1. Mouse click
  2. Mouse movement
  3. Key press

Is there a way to prevent this "Failed to load resource" error from occurring?

UPDATE: This seems to occur when the user's device sleeps/hibernates while still logged on...when the user restarts the device. This is when the error message can be seen on Chrome's Inspect Element, Firebug, etc.

UPDATE 10/02/2014: I have now condensed the five setTimeout functions into one large setTimeout function. In addition, the form that held the modify times in an input called "combinedfiletimeinput" has been removed and I now handle the file modify times differently.

Here is a screenshot of the Chrome Developer Tools log showing the error. I have added "mysite" in place of my site's name and "filename" in place of the actual filename. I have also whited out the name of the external JavaScript file, and all that remains is .js (sorry, but I'm just trying to be careful :) ) I cut off some of the screenshot, so the text would be large enough to read.

Chrome Screenshot

As you can see by the screenshot, the request processes OK for the first three requests. Then I "sleep"ed my device and then turned my device back on. That's where the next two requests are errors (in red). After these first two errors, the requests begin to process normally again (rows with black text, after rows with red text). The console clearly shows the error message.

Javascript Solutions


Solution 1 - Javascript

Just summarizing my comments under the question for community.

After some testing, it seems, that setting Ajax timeouts for every call is a must. Without timeouts, NET:: errors such as ERR_NETWORK_IO_SUSPENDED, ERR_INTERNET_DISCONNECTED, etc will cause Ajax to stop execution, and would not resume after computer wake up.

For jQuery:

$.ajax({
   url: yourURL,
   timeout: 4000
});

For XMLHttpRequest (XHR):

 xhr.timeout = 4000;

Moreover, an exception handler is necessary for your script to catch connection errors, so that your JavaScript code would not break down because of unexpected behavior/values.

Even with timeouts and exeption handler, your application will throw NET:: errors, but they would not harm your application; you could think of them as Notices.

Solution 2 - Javascript

As much as I think catching exceptions should be the general cure, you might try triggering fake (mouse, scroll, keyboard) events to see if that would prevent Chrome from going to "idle" status.

Stack Overflow question How to simulate a mouse click using JavaScript? might be helpful.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionThe One and Only ChemistryBlobView Question on Stackoverflow
Solution 1 - JavascriptAdam FischerView Answer on Stackoverflow
Solution 2 - JavascriptptrkView Answer on Stackoverflow