4

I have a javascript web app set up to use long polling with a .net server, using the ajax call:

var _listenTimeout = 5 * 60 * 1000;
//...
$.ajax({
      type: "GET",
      url: url,
      async: true,
      cache: false,
      dataType: "jsonp",
      timeout: _listenTimeout,
      success: callback
});

However, there is an issue when the page is open for a while, where requests to the server stop responding. It seems to be in a limbo state, where packets are stuck between the web browser and being sent out of the network to the server.

I've dug around, and I know a couple of things:

  • The request gets sent because it shows up on the chrome web developer network tab (also chrome://net-internals) and firebug. The status of the request is always pending, and it just stalls in that state.
  • The request url is correct, because sending the same url through curl returns an immediate response.
  • It hasn't left my network because there aren't any packets detected using wireshark. The server logs (and wireshark on that side) don't show anything either.

The strange thing is, sometimes it works sporadically, but with a delay of a couple of minutes ie, the browser network log detects the request gets a response (a 204 in my case), and wireshark detects the request being sent (and received on the server end). The delay is the same for both the browser and wireshark ie, the request is made, a delay occurs, then chrome detects a response and wireshare detects packets sent.

A clean refresh of the page also fixes the issue, with the same request/response occurring almost immediately (with the relevant browser network and wireshark logs).

I've tried it on Chrome 21.0.1180.89 and Firefox 14.01.

Is there some browser queue of some sort that gets clogged up in the browser with ajax requests? Or maybe too many concurrent requests? No idea right now...

Community
  • 1
  • 1
zlog
  • 3,316
  • 4
  • 42
  • 82
  • How long has `chrome://net-internals` existed? That is **awesome**! – Naftali Sep 20 '12 at 13:39
  • 1
    Can you elaborate a bit? Chrome shows that the request is being made, but you literally get no response... as in no headers or anything? But the connection is made? Wireshark shows no packets at all, or just not what you are expecting to see? Could you be sniffing on the wrong interface? – Brad Sep 20 '12 at 15:34
  • @Brad - have updated the question with more details. Hopefully, they answer all your questions, namely that wireshark does detect the same url requests on a clean page refresh. – zlog Sep 20 '12 at 16:42
  • `Is there some browser queue of some sort that gets clogged up in the browser with ajax requests? Or maybe too many concurrent requests?` yes it is, each browser has a limit that is "logical" to their designers. try my tester on [that](http://stackoverflow.com/a/5642478/443685) question. Also, I wonder, why do you abort ajax on browser side?? I think is beter to let the server anwser "no news" (after some time) and let the browser ask again (with a new ajax) – Saic Siquot Sep 20 '12 at 17:34
  • so in that way both sides ends the request normaly and clean – Saic Siquot Sep 20 '12 at 17:43
  • We are looking into refactoring the client/server interaction, but can't do so as yet. Thanks for the pointer to the script, although, I'm not sure whether we can run php. Also, it's very strange that a similar setup with similar requests on another development server works fine. Might look into the differences between the 2 setups. – zlog Sep 21 '12 at 08:44

1 Answers1

0

$.ajax wont make periodic requests. timeout option specifies the delay in making actual request not for polling. read about it here. http://api.jquery.com/jQuery.ajax/. Thats why you are seeing only one ajax request.If you want it manually you have to do it with setTimeout javascript method.

You can call setTimeout in the success and error callbacks so that you can get rid of concurrent ajax requests.

Amareswar
  • 2,048
  • 1
  • 20
  • 36
  • 1
    We are using long polling (http://en.wikipedia.org/wiki/Push_technology#Long_polling), so it should work. `setTimeout` does not work because the server would be pushing updates to the browser with the long poll. – zlog Sep 24 '12 at 09:26