sync ajax request runs all the time despite the interval in Firefox Developer Edition




2 years ago
a year ago


(Reporter: kamil.p, Unassigned)



52 Branch

Firefox Tracking Flags

(Not tracked)




2 years ago
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36

Steps to reproduce:

I set up 3s interval on my page by setInterval. Inside this interval I created ajax request with async: false. I run that script on Firefox Developer Edition 52.0a2 (2017-01-09) (64 bity).

Actual results:

Script was running all the time like in loop not interval. This same problem doesn't exist on normal Firefox 50.1.0 and Chrome 55.0.2883.87 m (64-bit).

Expected results:

Ajax request should be called every 3s not all the time.

Comment 1

2 years ago
Could you provide a testcase, please.
Component: JavaScript: Standard Library → DOM
Flags: needinfo?(kamil.p)
Keywords: testcase-wanted
How long do your sync xhrs take?

In bug 1303167 we changed how we account for time during sync xhr.  We previously would shift pending timers to the future during sync xhr.  So if:

* there is a pending timeout with 1 second remaining
* sync xhr is started and lasts 0.5 seconds
* the timeout would then fire at time 1.5 seconds (1.0 seconds after end of sync xhr)

Since bug 1303167 we now do this:

* there is a pending timeout 1 second remaining
* senc xhr is started and lasts 0.5 seconds
* the timeout now fires at time 1.0 seconds (only 0.5 seconds after end of sync xhr)

If the sync xhr takes longer than the pending timeout, then the timeout will fire immediately after the sync xhr.

Admittedly this is a web compatibility change, but it aligns sync xhr with how we have always handled modal dialogs.  We believe this new behavior is more correct.  AFAIK the spec does not go into detail about how timers should be handled in sync xhr.

If this is the problem you are experiencing you can change your code to trigger a new setTimeout() after sync xhr completes instead of using setInterval().
Boris pointed out in IRC my changes in bug 1303167 would not affect:

  function f() {
    // long sync xhr
  setInterval(f, 3000);

We don't schedule the next callback for the setInterval() until the callback completes.  My changes in bug 1303167 affect other timers that might have fired during the sync xhr.

Please provide a test case if you can.
Please re-open if you have time to create a test case. Seems like comments 2 and 3 answered at least part of the issue here.
Last Resolved: a year ago
Flags: needinfo?(kamil.p)
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.