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

Issue 19478003: Remove Thread wrapper class in forwarder2. (Closed)

Created:
7 years, 5 months ago by Philippe
Modified:
7 years, 4 months ago
Reviewers:
digit, bulach, pliard, digit1
CC:
chromium-reviews, craigdh+watch_chromium.org, bulach+watch_chromium.org, yfriedman+watch_chromium.org, ilevy-cc_chromium.org, klundberg+watch_chromium.org, frankf+watch_chromium.org
Visibility:
Public.

Description

Remove Thread wrapper class in forwarder2. This class unnecessarily reinvented the wheel in a non-RAII way that proved to be harmful (see r210830). Also, this class wasn't playing nicely with Chromium's base idioms. For instance it was impossible to do task posting with it. This implied some non-idiomatic threading code that was hard to read and reason about (e.g. using locks, pthread_condition_t...) thus hard to maintain and debug. See device_listener.cc for instance. This CL also refactors the shutdown code to ensure that in general all the objects are always destroyed on the thread they were created on. This wasn't the case before. BUG=242846 R=bulach@chromium.org, digit@google.com Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=214338

Patch Set 1 : #

Patch Set 2 : #

Patch Set 3 : Rebase #

Total comments: 19

Patch Set 4 : Address Digit's comments #

Total comments: 1

Patch Set 5 : Fix indent #

Patch Set 6 : Improve comments and DeleteHostController() #

Patch Set 7 : Remove unused forward declaration #

Total comments: 4

Patch Set 8 : Address Digit's comments #

Total comments: 5

Patch Set 9 : Address Marcus' comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+637 lines, -620 lines) Patch
M tools/android/forwarder2/command.h View 1 2 3 1 chunk +3 lines, -3 lines 0 comments Download
M tools/android/forwarder2/device_controller.h View 1 2 3 1 chunk +30 lines, -11 lines 0 comments Download
M tools/android/forwarder2/device_controller.cc View 1 2 3 4 5 6 7 1 chunk +118 lines, -106 lines 0 comments Download
M tools/android/forwarder2/device_forwarder_main.cc View 1 2 3 3 chunks +30 lines, -11 lines 0 comments Download
M tools/android/forwarder2/device_listener.h View 1 2 3 1 chunk +75 lines, -45 lines 0 comments Download
M tools/android/forwarder2/device_listener.cc View 1 2 3 4 1 chunk +110 lines, -150 lines 0 comments Download
M tools/android/forwarder2/forwarder.h View 1 chunk +4 lines, -24 lines 0 comments Download
M tools/android/forwarder2/forwarder.cc View 1 2 3 2 chunks +80 lines, -57 lines 0 comments Download
M tools/android/forwarder2/forwarder.gyp View 2 chunks +0 lines, -2 lines 0 comments Download
M tools/android/forwarder2/host_controller.h View 1 2 3 4 5 6 2 chunks +42 lines, -26 lines 0 comments Download
M tools/android/forwarder2/host_controller.cc View 1 2 3 3 chunks +102 lines, -84 lines 0 comments Download
M tools/android/forwarder2/host_forwarder_main.cc View 1 2 3 4 5 6 7 8 9 chunks +43 lines, -26 lines 0 comments Download
D tools/android/forwarder2/thread.h View 1 chunk +0 lines, -35 lines 0 comments Download
D tools/android/forwarder2/thread.cc View 1 chunk +0 lines, -40 lines 0 comments Download

Messages

Total messages: 14 (0 generated)
Philippe
7 years, 5 months ago (2013-07-17 15:26:30 UTC) #1
Philippe
Adding Marcus on this. This is a big cleanup CL which I realize might be ...
7 years, 5 months ago (2013-07-18 14:04:54 UTC) #2
digit1
https://chromiumcodereview.appspot.com/19478003/diff/49001/tools/android/forwarder2/device_controller.cc File tools/android/forwarder2/device_controller.cc (right): https://chromiumcodereview.appspot.com/19478003/diff/49001/tools/android/forwarder2/device_controller.cc#newcode44 tools/android/forwarder2/device_controller.cc:44: void DeviceController::AcceptClientSoon() { nit: I think AcceptHostCommandSoon() / AcceptHostCommand() ...
7 years, 5 months ago (2013-07-18 20:08:38 UTC) #3
Philippe
Thanks David! In addition to addressing your comments, I also had to improve the global ...
7 years, 5 months ago (2013-07-22 15:16:14 UTC) #4
Philippe
On 2013/07/22 15:16:14, Philippe wrote: > Thanks David! > > In addition to addressing your ...
7 years, 4 months ago (2013-07-29 13:56:34 UTC) #5
digit
lgtm. Thanks you for all the additional comments :)
7 years, 4 months ago (2013-07-29 18:11:48 UTC) #6
digit
https://chromiumcodereview.appspot.com/19478003/diff/14002/tools/android/forwarder2/device_controller.cc File tools/android/forwarder2/device_controller.cc (right): https://chromiumcodereview.appspot.com/19478003/diff/14002/tools/android/forwarder2/device_controller.cc#newcode73 tools/android/forwarder2/device_controller.cc:73: base::Unretained(this))); I'm a bit sad that we have to ...
7 years, 4 months ago (2013-07-29 18:11:59 UTC) #7
Philippe
Thanks David! https://chromiumcodereview.appspot.com/19478003/diff/14002/tools/android/forwarder2/device_controller.cc File tools/android/forwarder2/device_controller.cc (right): https://chromiumcodereview.appspot.com/19478003/diff/14002/tools/android/forwarder2/device_controller.cc#newcode73 tools/android/forwarder2/device_controller.cc:73: base::Unretained(this))); On 2013/07/29 18:11:59, digit wrote: > ...
7 years, 4 months ago (2013-07-30 09:37:18 UTC) #8
bulach
lgtm, thanks!! just some questions below: https://codereview.chromium.org/19478003/diff/89001/tools/android/forwarder2/forwarder.cc File tools/android/forwarder2/forwarder.cc (right): https://codereview.chromium.org/19478003/diff/89001/tools/android/forwarder2/forwarder.cc#newcode132 tools/android/forwarder2/forwarder.cc:132: if (HANDLE_EINTR(select(nfds, &read_fds, ...
7 years, 4 months ago (2013-07-30 11:11:36 UTC) #9
pliard
Thanks Marcus! https://codereview.chromium.org/19478003/diff/89001/tools/android/forwarder2/forwarder.cc File tools/android/forwarder2/forwarder.cc (right): https://codereview.chromium.org/19478003/diff/89001/tools/android/forwarder2/forwarder.cc#newcode132 tools/android/forwarder2/forwarder.cc:132: if (HANDLE_EINTR(select(nfds, &read_fds, &write_fds, NULL, NULL)) <= ...
7 years, 4 months ago (2013-07-30 11:50:20 UTC) #10
pliard
FYI, I'm landing this now so that I can monitor the tree for a few ...
7 years, 4 months ago (2013-07-30 12:03:05 UTC) #11
Philippe
Committed patchset #9 manually as r214338 (presubmit successful).
7 years, 4 months ago (2013-07-30 12:13:36 UTC) #12
bulach
still lgtm :) https://codereview.chromium.org/19478003/diff/89001/tools/android/forwarder2/forwarder.cc File tools/android/forwarder2/forwarder.cc (right): https://codereview.chromium.org/19478003/diff/89001/tools/android/forwarder2/forwarder.cc#newcode132 tools/android/forwarder2/forwarder.cc:132: if (HANDLE_EINTR(select(nfds, &read_fds, &write_fds, NULL, NULL)) ...
7 years, 4 months ago (2013-07-30 13:11:44 UTC) #13
pliard
7 years, 4 months ago (2013-07-30 13:42:15 UTC) #14
Thanks Marcus! Ah I understand better now :) I had this hanging issue in
mind and misunderstood.

So you are exactly right and the forwarder commands (including connection
redirection setup/teardown and process killing) are all synchronous now.
The process that is used to trigger the commands (and that talks to the
daemon through a Unix Domain Socket) only returns after the daemon notified
it (which happens when the operations completed). We already tear
down/setup race conditions in the past because we were using plain kill
commands which are asynchronous. This was replaced will a '--kill-server'
parameter to make it synchronous.

And yeah I intend to re-land the other CL soon once Pawel approved the CL
in testserver.py. I had yet another fun debugging session with that :)


On Tue, Jul 30, 2013 at 3:11 PM, <bulach@chromium.org> wrote:

> still lgtm :)
>
>
>
> https://codereview.chromium.**org/19478003/diff/89001/tools/**
>
android/forwarder2/forwarder.**cc<https://codereview.chromium.org/19478003/diff/89001/tools/android/forwarder2/forwarder.cc>
> File tools/android/forwarder2/**forwarder.cc (right):
>
> https://codereview.chromium.**org/19478003/diff/89001/tools/**
>
android/forwarder2/forwarder.**cc#newcode132<https://codereview.chromium.org/19478003/diff/89001/tools/android/forwarder2/forwarder.cc#newcode132>
> tools/android/forwarder2/**forwarder.cc:132: if (HANDLE_EINTR(select(nfds,
> &read_fds, &write_fds, NULL, NULL)) <= 0) {
> On 2013/07/30 11:50:20, pliard wrote:
>
>> On 2013/07/30 11:11:37, bulach wrote:
>> > there are too many layers, so apologies for what could be a silly
>>
> question :)
>
>> > I think we always start roughly in this order:
>> > WPR
>> > forwarder
>> > chrome
>> >
>> > however, if chrome for some reason hangs, or say, didn't finish the
>>
> test, the
>
>> > next bot run will do the above, and afaict, it'd kill each one of
>>
> the above
>
>> > individually...
>> >
>> > once we kill wpr, or the host forwarder, would this be propagated
>>
> all the way
>
>> > down here?
>> >
>> > or in another way: is there a case where both read and write fds
>>
> here are
>
>> valid
>> > and we'd not receive an EINTR, so that this thread would never be
>>
> able to
>
>> join?
>>
>
>  This is a non-trivial question so not silly at all :)
>>
>
>  I'm not sure I fully understand it but I will do my best: select()
>>
> should return
>
>> as soon as there is any event on at least one of the sockets.
>> So any side doing a close() would trigger the self-deletion of this
>>
> class.Note
>
>> that this class runs both on the host and the device.
>>
>
>  The global shutdown situation (through a kill) here could be improved
>>
> by using a
>
>> "PipeNotifier" as we do in other places. Currently if one of the two
>>
> processes
>
>> (host_forwarder or device_forwarder) is killed, we are (rather
>>
> unintentionally)
>
>> relying on the fact that the file descriptors are automatically
>>
> closed. The
>
>> other side would see a close on the corresponding socket. I will send
>>
> a follow
>
>> up CL to improve that (by using a PipeNotifier here). I don't expect
>>
> it to cause
>
>> any behavioral change though.
>>
>
>  What do you think?
>>
>
>  Are you referring to the bug where you could see ~16 threads blocked
>>
> here on
>
>> select()?
>> I will try to reproduce the hang with this CL.
>>
>
> thanks for the detailed explanation!
> agree with going ahead with this patch, just some more details on the
> case I was thinking:
> 1) run a test where chrome loads a URL, but for whatever reason, it
> doesn't complete (or perhaps that request had a Keep-Alive)
>
> 2) way, way higher up would eventually fail the test, like a timeout on
> buildbot, or telemetry, etc... at this stage, all components (WPR,
> forwarder, chrome), are left behind in an unknown state... afaict, both
> forwarders would be blocked at this select() here.
>
> 3) next run comes along. at this point, I think we'd first try to kill
> the WPR, then forwarder, then chrome... so if I understand correctly,
> the flow at this point is:
> 3.1) kill WPR
> 3.2) close the socket.
> 3.3) unblock here, close the host forwarder
> 3.4) which would unblock the device forwarder
> 4) start the forwarder
> 5) start chrome, run the test
>
> So I guess it will fit together nicely, right? :)
>
> ...unless.. (3.4) and (4) are async, and potentially 4 happens before...
> I guess with the other change making the forwarder API synchronized at
> the python level this shouldn't happen, but anyways..
>
>
https://codereview.chromium.**org/19478003/<https://codereview.chromium.org/1...
>

Powered by Google App Engine
This is Rietveld 408576698