Closed Bug 1663590 Opened 4 years ago Closed 10 months ago

XHR.timeout is affected by long tasks

Categories

(Core :: DOM: Networking, defect, P3)

defect

Tracking

()

RESOLVED INVALID
Tracking Status
firefox80 --- affected
firefox81 --- affected
firefox82 --- affected

People

(Reporter: samuel.elg, Unassigned)

References

(Blocks 1 open bug)

Details

(Whiteboard: [necko-triaged])

Attachments

(1 file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36

Steps to reproduce:

A zip file with the front and back-end needed to reproduce this issue is attached.

  1. Open the zip file, and serve that folder (in mac you can run "http-serve") and visit the index.html file.
  2. The folder has a "server.js" file. Run it with "node server.js."
  3. Refresh multiple times, and you will see that sometimes the timeout callback is called, even though it shouldn't (console will log "timeout!").

What the script and server reproduce:

  1. The timeout is set to 1000ms.
  2. The request is made.
  3. A blocking script is running for 2000ms (a while loop).
  4. The server responds in 100ms (concurrently to step 3).
  5. The timeout callback is called, and the request is canceled.

Actual results:

The request is canceled and the timeout callback is called.

Expected results:

The request should not be canceled (chrome behaves correctly, safari has the same issue).
It seems like the timer counting the time of the request is running on the main thread and therefore affected by long tasks, this should not be the case.

Hi Samuel,

You forgot the attachment :)

Regards, Flor.

Flags: needinfo?(samuel.elg)
Attached file timeout-bug.zip

The forgotten attachment....

Flags: needinfo?(samuel.elg)

Thanks, Flor!
I added the attachment.
Here is the fixed bug in webkit for reference: https://bugs.webkit.org/show_bug.cgi?id=216266

Hi Samuel,

Thanks for the details. I was able to reproduce the bug on Windows 10 on the following versions:

	Release 80.0 (64-bit) and Nightly 82.0a1 (2020-09-20) (64-bit).

I believe that the severity is S4 or S3. I've chosen a component. If you consider that there's another component that's more proper for this case you may change it.

Best regards, Flor.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core
Version: Firefox 81 → Trunk

Seems the last active person in XHR was :smaug. Mind taking a look?

Severity: -- → S3
Component: DOM: Core & HTML → DOM: Networking
Flags: needinfo?(bugs)

Timer should count time, it is not specific to to any threads. So if main thread has some long running JS, xhr timeout should fire.
The spec has:

Run these steps in parallel:
Wait until either req’s done flag is set or
the timeout attribute value number of milliseconds has passed since these steps started
while timeout attribute value is not zero.
If req’s done flag is unset, then set the timed out flag and terminate fetching.

https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send

Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago
Resolution: --- → INVALID

oh, hmm
perhaps
"If req’s done flag is unset, then set the timed out flag and terminate fetching. "

Status: RESOLVED → REOPENED
Ever confirmed: true
Flags: needinfo?(bugs)
Resolution: INVALID → ---

The spec is inherently racy here, since it is possible that done flag isn't set before timed out flag. Nothing defines the order of those.

Could you perhaps file a spec issue on this?

(In reply to Olli Pettay [:smaug] from comment #8)

The spec is inherently racy here, since it is possible that done flag isn't set before timed out flag. Nothing defines the order of those.

Could you perhaps file a spec issue on this?

Anne, could you help to do this?

Severity: S3 → S4
Flags: needinfo?(annevk)
Priority: -- → P3
Whiteboard: [necko-triaged]

I don't understand the race you are concerned about. The timed out flag is only set when the done flag is unset (for asynchronous XHR). (For synchronous XHR there is no done flag.) So there is a race between the request being done and it timing out, but that is needed for the feature to work. 😊

Flags: needinfo?(annevk) → needinfo?(bugs)
Blocks: xhr
Status: REOPENED → NEW

Ah, isn't this just about the order of timer and network response, which isn't guaranteed.
"Wait until either req’s done flag is set or this’s timeout is not 0 and this’s timeout milliseconds have passed since now. "

Status: NEW → RESOLVED
Closed: 4 years ago10 months ago
Flags: needinfo?(smaug)
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: