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

Issue 684141 link

Starred by 3 users

Issue metadata

Status: Archived
Owner:
Closed: Feb 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 1
Type: Bug



Sign in to add a comment

trunks unit tests are flaky: WeakPtrs must be invalidated on the same sequenced thread.

Project Member Reported by ravisadineni@chromium.org, Jan 23 2017

Issue description

Seems to be the same issue as  issue 681254 .
Can't reproduce on my system with ToT, so probably indeed a flaky test.
Summary: trunks unit tests are flaky: WeakPtrs must be invalidated on the same sequenced thread. (was: Reef-paladin : trunk unit tests is failing)
 Issue 681254  has been merged into this issue.
Occasionally BackgroundTransceiverTest.Synchronous unit test crashes on systems where trunksd is built (reef, gru, ...) with the following error:

FATAL:weak_ptr.cc(20)] Check failed: sequence_checker_.CalledOnValidSequencedThread() || HasOneRef(). WeakPtrs must be invalidated on the same sequenced thread.
Apparently, this is a rarely happening race condition:

We return from BackgroundCommandTransceiver::SendCommandAndWait() and then from run_loop.RunUntilIdle() in the unit test as soon as the response_ready event is signaled.

However, the SendCommandTask on test_thread_ may still be running and this holding base::WeakPtr<BackgroundCommandTransceiver> after signaling the event. If the caller (BackgroundCommandTransciever::task_runner_) is immediately woken up inside event->Signal(), SendCommandTask may still be running after run_loop.RunUntilIdle() and at the end if the unit test.

And then, if SendCommandTask is still running by the time we finish the test, the background_transceiver destructor will start with destructing the transciever's internal weak_factory_, which still holds a pointer used by SendCommandTask. Hence the error. 

This condition can easily be replicated by adding sleep after event->Signal() to the end of AssignAndSignal() in background_command_transceiver.cc.
Adding test_thread_.Stop() to the end of BackgroundTransceiverTest.Synchronous resolves the issue.

However, needs to be investigated if in real-life usage scenarios (aosp/system/tpm/trunks/trunksd.cc, platform2/chaps/tpm2_utility_impl.cc) the underlying transcever threads are properly stopped.

Or, it is needed to rework BackgroundCommandTransceiver to use something like PostTaskAndReplyWithResult instead of homegrown reply handling.
Components: OS>Systems
Labels: OS-Chrome
- For chapsd, TPM2UtilityImpl is constructed from tpm_background_thread.task_runner() and passes it to BackgroundCommandTransceiver. Stop() is called for tpm_background_thread in chapsd.cc, so we are ok. 

- For trunksd, BackgroundCommandTransceiver is constructed with background_thread.task_runner(), and background_thread is not stopped before destructing background_transceiver. So, this race is possible.

Blockedon: 687018
Status: Started (was: Assigned)
For trunksd, the daemon shutdown logic is being reviewed in  issue 687018 .
At this moment, there's no issue with WeakPtrs, but it will need to be checked again after fixing that issue with shutdown logic.
Blockedon: -687018
Status: Fixed (was: Started)
The CL https://chromium-review.googlesource.com/#/c/431503/ has actually landed, just not reflected here. 
Removing blockedon  issue 687018  - no WeakPtr issues observed fro trunksd after adding proper shutdown.

Comment 10 by dchan@google.com, Apr 17 2017

Labels: VerifyIn-59

Comment 11 by dchan@google.com, May 30 2017

Labels: VerifyIn-60
Labels: VerifyIn-61

Comment 13 by dchan@chromium.org, Oct 14 2017

Status: Archived (was: Fixed)

Sign in to add a comment