New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 758455 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Last visit > 30 days ago
Closed: Sep 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug
Proj-Servicification

Blocking:
issue 715640



Sign in to add a comment

ServiceWorkerURLLoaderJob should wait for the stream to finish before completing

Project Member Reported by falken@chromium.org, Aug 24 2017

Issue description

In ServiceWorkerURLLoaderJob::StartResponse, we do:

  // Handle a stream response body.
  if (!body_as_stream.is_null() && body_as_stream->stream.is_valid()) {
    CommitResponseHeaders();
    url_loader_client_->OnStartLoadingResponseBody(
        std::move(body_as_stream->stream));
    CommitCompleted(net::OK);
    return;
  }

But we shouldn't call url_loader_client_->OnComplete() until the stream successfully completes.
 

Comment 1 by falken@chromium.org, Aug 24 2017

Cc: yhirano@chromium.org
Actually I'm not totally sure this is a bug. We give the stream to the URLLoaderClient via OnStartLoadingResponseBody and maybe from then on it's the Client's job to read the stream and detect any failures?

Not sure what's the intended contract of URLLoaderClient. When talking to kinuko@ it sounded like OnComplete() should be called only after the response body finished loading completely. But I'm not sure that if currently we have an actual bug or if changing the OnComplete() call will affect real behavior (AFAICT, once  NavigationURLLoaderNetworkService::OnStartLoadingResponseBody() is called we commit the navigation to the renderer, so it might be too late for OnComplete() to have any effect).

Comment 2 by kinuko@chromium.org, Aug 24 2017

OnComplete is supposed to provide some metrics like transferred bytes / timing info, and they can surface at Performance Timing API.

(Separately from that I also have wondered if we could loosen that part after OnStartLoadingResponseBody is called and data pipe is given to the client, which makes the use cases like this, i.e. just passing the given data pipe to the loader client, really easy)

Comment 3 by falken@chromium.org, Aug 25 2017

(memo from offline chat) yhirano says the interface is intended to call OnComplete after all data has finished being written. Since SWUrlLoaderJob doesn't know when that is, either we need to add a new signal from the service worker to the loader, or have the loader create an intermediate data pipe and mediate data transfer from SW to the URL loader client. yhirano suggests asking Mojo team for a native solution and says this has been discussed before.
Project Member

Comment 4 by bugdroid1@chromium.org, Aug 25 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/19a781d5c693db99f8c1dcc4e4cd7c3844796e58

commit 19a781d5c693db99f8c1dcc4e4cd7c3844796e58
Author: Emi Morikawa <emim@google.com>
Date: Fri Aug 25 07:53:39 2017

Add more ServiceWorkerURLLoaderJob tests: stream response abort.

Bug:  748416 , 758455 
Change-Id: I588f541fde654339e73c01852419992911ac6af9
Reviewed-on: https://chromium-review.googlesource.com/631080
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Makoto Shimazu <shimazu@chromium.org>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Commit-Queue: Emi Morikawa <emim@google.com>
Cr-Commit-Position: refs/heads/master@{#497350}
[modify] https://crrev.com/19a781d5c693db99f8c1dcc4e4cd7c3844796e58/content/browser/service_worker/service_worker_url_loader_job.cc
[modify] https://crrev.com/19a781d5c693db99f8c1dcc4e4cd7c3844796e58/content/browser/service_worker/service_worker_url_loader_job_unittest.cc

Project Member

Comment 5 by bugdroid1@chromium.org, Aug 28 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/fd0efa6a9192b26f257bb2aa3c4135dbec38ce37

commit fd0efa6a9192b26f257bb2aa3c4135dbec38ce37
Author: Emi Morikawa <emim@google.com>
Date: Mon Aug 28 10:37:00 2017

Add more ServiceWorkerURLLoaderJob tests: stream response and cancel.

Bug:  748416 ,  758455 
Change-Id: Ie6f103f9bc6de2a59192648f4b7526a5d3a13076
Reviewed-on: https://chromium-review.googlesource.com/637060
Commit-Queue: Emi Morikawa <emim@google.com>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#497729}
[modify] https://crrev.com/fd0efa6a9192b26f257bb2aa3c4135dbec38ce37/content/browser/service_worker/service_worker_url_loader_job_unittest.cc

Comment 6 by falken@chromium.org, Aug 31 2017

Owner: emim@google.com
I learned we already have the mechanism set up via ServiceWorkerStreamHandle and ServiceWorkerStreamCallback interfaces. The SWStreamCallback::OnCompleted() is called when the response body finishes, and OnAborted() is called on error.

We should port what ServiceWorkerURLRequestJob and ServiceWorkerDataPipeReader do to ServiceWorkerURLLoaderJob.

I think we don't need all of SWDataPipeReader, just need to make a mojom::ServiceWorkerStreamCallback implementation in SWURLLoaderJob so that when OnCompleted() is called we CommitCompleted(OK) and when OnAborted is called we CommitCompleted(ERR).

We also need to do what SWDataPipeReader does with streaming_version->AddStreamingURLRequestJob(). This lets everyone know the service worker is still doing work, even though the fetch event may have already finished. 

Comment 7 by emim@google.com, Sep 11 2017

Status: Started (was: Assigned)
Project Member

Comment 9 by bugdroid1@chromium.org, Sep 12 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/9f173b376d00e590375290b8aba3f205e8f74c9e

commit 9f173b376d00e590375290b8aba3f205e8f74c9e
Author: Emi Morikawa <emim@google.com>
Date: Tue Sep 12 09:18:38 2017

ServiceWorker: Use counter for monitoring the number of ongoing stream responses.

Use counter instead of using pointers in ServiceWorkerVersion.

Bug:  758455 
Change-Id: I4fc5205940e18b130be17c52fbcea3e56246fd0e
Reviewed-on: https://chromium-review.googlesource.com/662004
Commit-Queue: Emi Morikawa <emim@google.com>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501223}
[modify] https://crrev.com/9f173b376d00e590375290b8aba3f205e8f74c9e/content/browser/service_worker/service_worker_data_pipe_reader.cc
[modify] https://crrev.com/9f173b376d00e590375290b8aba3f205e8f74c9e/content/browser/service_worker/service_worker_url_loader_job.cc
[modify] https://crrev.com/9f173b376d00e590375290b8aba3f205e8f74c9e/content/browser/service_worker/service_worker_version.cc
[modify] https://crrev.com/9f173b376d00e590375290b8aba3f205e8f74c9e/content/browser/service_worker/service_worker_version.h

Comment 10 by emim@google.com, Sep 19 2017

Status: Fixed (was: Started)
Components: Internals>Network>Service
Components: -Internals>Network>Service Internals>Services>Network
Apologies, applied the wrong component in bulk.

Sign in to add a comment