Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(984)

Issue 887863002: The ReadFile API on Windows invoked by the FileStream::Context class which is used by URLRequestFil… (Closed)

Created:
5 years, 10 months ago by ananta
Modified:
5 years, 10 months ago
CC:
chromium-reviews, cbentzel+watch_chromium.org, rvargas (doing something else)
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

The ReadFile API on Windows invoked by the FileStream::Context class which is used by URLRequestFileJob at times completes synchronously. The FileStream::Context class is used by the URLRequestFileJob class on the IO thread. The intention here is to open the file for overlapped IO and thus complete the read and writes asynchonously. Turns out that there are cases where the ReadFile API completes synchronously which ends up blocking the IO thread. http://support.microsoft.com/kb/156932 Fix for this is to post the ReadFile call to a worker pool and inform the caller about failures etc on the calling thread. Changes in this patch are as below:- 1. The FileStream::Context::Read function posts the ReadFile call to the Worker thread pool. The entry point for this task is the static function ReadAsync. This function posts results back to the originating thread via the function ReadAsyncResult 2. Fixed the FileStreamTest.WriteRead test to not read the data in the completion callback of the stream Write function. This causes a DCHECK to fire in the MessageLoopForIO class that we are entering a nested loop which is a no no for that message pump type. This DCHECK fires because of the change on Windows to execute the ReadFile in a Worker thread pool. In any case this change is safe for all platforms. The written data is validated by reading it back in the function ValidateWrittenData in the TestWriteReadCompletionCallback class. We call this explicitly in the FileStreamTest.WriteRead test. 3. Fix the SyncableFileOperationRunnerTest.CopyAndMove test failures. This test internally initiates a ReadFile call on Windows via the FileStream::Context class for the Copy and Move test. It invokes Copy and Move and then calls MessageLoop::RunUntilIdle. This call basically runs the message loop until all pending tasks and events have been processed. This works on Windows by fluke because the ReadFile call which completes asynchronously posts IO completion tasks to the IO thread (current thread) which then get pulled out by the RunUntilIdle call. There could be cases where the ReadFile call does not post IO completion events before RunUntilIdle returns and we could see the same failures. Reason we see this with this patch is because ReadFile is now completed by a worker pool thread which basically guarantees the above scenario. Fix is to use base::RunLoop::Run() and Quit the loop when the DidFinish callback is received. I changed all places in the syncable_file_operation_runner_unittest.cc file to use base::RunLoop::Run() or base::RunLoop::RunUntilIdle() as the MessageLoop equivalents are deprecated. BUG=423948 Committed: https://crrev.com/959eaea45546260d8517de3d1cabace790c5b5a7 Cr-Commit-Position: refs/heads/master@{#314388}

Patch Set 1 #

Patch Set 2 : Fixed test failures #

Patch Set 3 : Fix weakptr usage #

Patch Set 4 : Ensure that the weak pointers are invalidated on Windows when the context is orphaned. #

Total comments: 4

Patch Set 5 : Fix the SyncableFileOperationRunnerTest.CopyAndMove test failures #

Patch Set 6 : Address review comments #

Patch Set 7 : Pass the result of ReadFile on failure only #

Total comments: 4
Unified diffs Side-by-side diffs Delta from patch set Stats (+121 lines, -45 lines) Patch
M chrome/browser/sync_file_system/local/syncable_file_operation_runner_unittest.cc View 1 2 3 4 12 chunks +16 lines, -14 lines 0 comments Download
M net/base/file_stream_context.h View 1 2 3 4 5 3 chunks +32 lines, -0 lines 0 comments Download
M net/base/file_stream_context.cc View 1 2 3 1 chunk +6 lines, -0 lines 0 comments Download
M net/base/file_stream_context_win.cc View 1 2 3 4 5 6 5 chunks +46 lines, -15 lines 4 comments Download
M net/base/file_stream_unittest.cc View 1 3 chunks +21 lines, -16 lines 0 comments Download

Messages

Total messages: 14 (4 generated)
ananta
5 years, 10 months ago (2015-01-30 02:40:46 UTC) #2
ananta
5 years, 10 months ago (2015-01-31 02:22:06 UTC) #4
ramant (doing other things)
lgtm https://codereview.chromium.org/887863002/diff/60001/net/base/file_stream_context.h File net/base/file_stream_context.h (right): https://codereview.chromium.org/887863002/diff/60001/net/base/file_stream_context.h#newcode169 net/base/file_stream_context.h:169: // pool nit: period on line# 169. "pool" ...
5 years, 10 months ago (2015-01-31 05:23:22 UTC) #5
ananta
https://codereview.chromium.org/887863002/diff/60001/net/base/file_stream_context.h File net/base/file_stream_context.h (right): https://codereview.chromium.org/887863002/diff/60001/net/base/file_stream_context.h#newcode169 net/base/file_stream_context.h:169: // pool On 2015/01/31 05:23:22, ramant wrote: > nit: ...
5 years, 10 months ago (2015-02-03 00:33:43 UTC) #6
cpu_(ooo_6.6-7.5)
lgtm for syncable_file_operation_runner_unittest.cc I did not look at the net code. I don't know if ...
5 years, 10 months ago (2015-02-03 03:11:15 UTC) #7
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/887863002/120001
5 years, 10 months ago (2015-02-03 19:47:16 UTC) #9
commit-bot: I haz the power
Committed patchset #7 (id:120001)
5 years, 10 months ago (2015-02-03 19:51:17 UTC) #10
commit-bot: I haz the power
Patchset 7 (id:??) landed as https://crrev.com/959eaea45546260d8517de3d1cabace790c5b5a7 Cr-Commit-Position: refs/heads/master@{#314388}
5 years, 10 months ago (2015-02-03 19:52:08 UTC) #11
rvargas (doing something else)
https://codereview.chromium.org/887863002/diff/120001/net/base/file_stream_context_win.cc File net/base/file_stream_context_win.cc (right): https://codereview.chromium.org/887863002/diff/120001/net/base/file_stream_context_win.cc#newcode82 net/base/file_stream_context_win.cc:82: weak_ptr_factory_.GetWeakPtr(), file_.GetPlatformFile(), This passes a raw handle across a ...
5 years, 10 months ago (2015-02-03 20:04:37 UTC) #13
ananta
5 years, 10 months ago (2015-02-04 01:55:39 UTC) #14
Message was sent while issue was closed.
https://codereview.chromium.org/887863002/diff/120001/net/base/file_stream_co...
File net/base/file_stream_context_win.cc (right):

https://codereview.chromium.org/887863002/diff/120001/net/base/file_stream_co...
net/base/file_stream_context_win.cc:82: weak_ptr_factory_.GetWeakPtr(),
file_.GetPlatformFile(),
On 2015/02/03 20:04:37, rvargas wrote:
> Isn't _this_ pointer being used from multiple threads?

The weakptr is only used for passing the results back to the main thread. As per
our discussion the context object would not go away before the read completes on
the worker pool. so we should be ok.

https://codereview.chromium.org/887863002/diff/120001/net/base/file_stream_co...
net/base/file_stream_context_win.cc:82: weak_ptr_factory_.GetWeakPtr(),
file_.GetPlatformFile(),
On 2015/02/03 20:04:37, rvargas wrote:
> This passes a raw handle across a thread boundary without transferring
> ownership. Please don't do that.

Ditto about the context object living as long as the Read does not complete on
the worker thread. As per discussion leaving this as is.

Powered by Google App Engine
This is Rietveld 408576698