Open Bug 1540640 Opened 5 years ago Updated 2 years ago

Download via ReadableStream : cancel is called on pause

Categories

(Core :: DOM: Service Workers, enhancement, P3)

66 Branch
enhancement

Tracking

()

UNCONFIRMED

People

(Reporter: zurldan, Unassigned)

Details

Attachments

(1 file)

1.44 KB, application/zip
Details
Attached file case.zip

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0

Steps to reproduce:

(I attached a zip archive containing the index.html and service worker in a in order to reproduce)

In my index.html I register a service worker and I display 2 links to download a txt file and a png file. The txt file will be generated via a ReadableStream in the service worker. This stream has a CountQueuingStrategy with a highWaterMark of 3. Each pull log the controller.desiredSize in the console. I open the console and then click on the txt file link. The browser shows a popup that asks if I want to open / save / cancel the file. I accept and then go to the Firefox download manager, right click on the download and click pause.

Additional information :

This requires a web server in order to work, if index.html is opened directly in a browser, the service worker registration fails with this message in the console :

Registration failed with SecurityError: The operation is insecure.

If you need a simple web server to test it, you can go into the case directory, open a terminal there and run one of those commands :

// python 2.7
python -m SimpleHTTPServer

// python 3
python -m http.server

// php
php -S localhost:8000

Then you can open your browser and go to http://localhost:8000 and it should work.

Actual results:

We can see in the console that 'canceled' appears. Meaning that the cancel() method was called on the ReadableStream when 'Pause' was clicked.

Expected results:

It should just stop consuming the stream when clicking pause, not cancel it, and start consuming the stream again when the download is resumed.

Component: Untriaged → JavaScript Engine
Product: Firefox → Core
Flags: needinfo?(jorendorff)
Flags: needinfo?(jorendorff)
Priority: -- → P2
Flags: needinfo?(jorendorff)

From the description, it sounds like a normal cancellation is happening. The stream itself is just doing what it's told. So I think the bug must be on the DOM side, or maybe something further downstream like the Download Manager.

Component: JavaScript Engine → DOM: Service Workers
Flags: needinfo?(jorendorff) → needinfo?(amarchesini)
Priority: P2 → --

The download manager cancels the request when a download is paused. Because of this, we close the inputStream. At this point, the operation cannot be restored. Wondering if we should allow the pausing of a download generated from a ReadableStream.

Andrew, do you know how downloads are resumed when there are ServiceWorkers involved? A new channel is created passing a range header?

Flags: needinfo?(amarchesini) → needinfo?(bugmail)

Obviously we should be using TCP flow control to pause downloads instead ;-)

There's a spec issue on what ServiceWorkers should do, https://github.com/w3c/ServiceWorker/issues/1201. Right now ServiceWorkers will intentionally error out.

Research Notes

The download logic appears to use[1] nsIResumableChannel.resumeAt[2] when starting a download that already has data.

ServiceWorkers do not support resumption via this mechanism at this time. InterceptedHttpChannel implements resumeAt[3] but it's only for hand-off when interception is reset[4], with an error explicitly generated[5] if StartPump() is called and mResumeStartPos > 0.

1: https://searchfox.org/mozilla-central/rev/7556a400affa9eb99e522d2d17c40689fa23a729/toolkit/components/downloads/DownloadCore.jsm#1931
2: https://searchfox.org/mozilla-central/rev/7556a400affa9eb99e522d2d17c40689fa23a729/netwerk/base/nsIResumableChannel.idl#12
3: https://searchfox.org/mozilla-central/rev/7556a400affa9eb99e522d2d17c40689fa23a729/netwerk/protocol/http/InterceptedHttpChannel.cpp#590
4: https://searchfox.org/mozilla-central/rev/7556a400affa9eb99e522d2d17c40689fa23a729/netwerk/protocol/http/InterceptedHttpChannel.cpp#71
5: https://searchfox.org/mozilla-central/rev/7556a400affa9eb99e522d2d17c40689fa23a729/netwerk/protocol/http/InterceptedHttpChannel.cpp#293

Flags: needinfo?(bugmail)
Type: defect → enhancement
Priority: -- → P3
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: