Skip to content

Commit

Permalink
Fix crash in net fetcher (#713) (#784)
Browse files Browse the repository at this point in the history
Crash could occur because of concurrent execution of GetLoadTiminInfo and Stop.
The problem solved by let the content of the GetLoadTimingInfo function
(i.e. ReportLoadTimingInfo) be executed by the delegate thread.

b/266121186

Change-Id: I5249ed823c3cf9ff230e18cfa660a42347c9da99
(cherry picked from commit d0e1689)

Co-authored-by: MichaelSweden <MichaelSweden@users.noreply.github.com>
  • Loading branch information
cobalt-github-releaser-bot and MichaelSweden committed Jun 29, 2023
1 parent 644fa42 commit c54630d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion net/url_request/url_fetcher_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ void URLFetcherCore::Start() {
}

void URLFetcherCore::Stop() {
if (delegate_task_runner_) // May be NULL in tests.
if (delegate_task_runner_) { // May be NULL in tests.
DCHECK(delegate_task_runner_->RunsTasksInCurrentSequence());
}

delegate_ = NULL;
fetcher_ = NULL;
Expand Down Expand Up @@ -779,8 +780,11 @@ void URLFetcherCore::StartURLRequest() {
if (!extra_request_headers_.IsEmpty())
request_->SetExtraRequestHeaders(extra_request_headers_);

#if defined(STARBOARD)
request_->SetLoadTimingInfoCallback(base::Bind(&URLFetcherCore::GetLoadTimingInfo,
base::Unretained(this)));
#endif

request_->Start();
}

Expand Down Expand Up @@ -1129,6 +1133,14 @@ void URLFetcherCore::AssertHasNoUploadData() const {
#if defined(STARBOARD)
void URLFetcherCore::GetLoadTimingInfo(
const net::LoadTimingInfo& timing_info) {
delegate_task_runner_->PostTask(
FROM_HERE,
base::Bind(&URLFetcherCore::GetLoadTimingInfoInDelegateThread,
this, timing_info));
}

void URLFetcherCore::GetLoadTimingInfoInDelegateThread(
const net::LoadTimingInfo& timing_info) {
// Check if the URLFetcherCore has been stopped before.
if (delegate_) {
delegate_->ReportLoadTimingInfo(timing_info);
Expand Down
1 change: 1 addition & 0 deletions net/url_request/url_fetcher_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class URLFetcherCore : public base::RefCountedThreadSafe<URLFetcherCore>,
static void SetIgnoreCertificateRequests(bool ignored);
#if defined (STARBOARD)
void GetLoadTimingInfo(const net::LoadTimingInfo& timing_info);
void GetLoadTimingInfoInDelegateThread(const net::LoadTimingInfo& timing_info);
#endif // defined(STARBOARD)
private:
friend class base::RefCountedThreadSafe<URLFetcherCore>;
Expand Down

0 comments on commit c54630d

Please sign in to comment.