0

Fix DirectReceiverTest.ThreadLocalInstanceShared unit tests

The unit test sometimes hits a nullptr exception when running this
test. Roughly 1 out of 1000 iterations on x86 when running locally.

The problem comes from the loop in
ThreadLocalNode::WatchForIncomingTransfers. The context variable is
released and if the loop actually start over we send in a nullptr when
installing the trap. We later crash in ThreadLocalNode::OnTrapEvent,
trying to use this pointer.

Fix this by only releasing the unique_ptr on successful trap
installation. The recursive call is also removed letting the loop
handle retries on its own.

R=rockot

Change-Id: I5dff130aee08ed0c923a5d39bd72aba2ba6907d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4909591
Reviewed-by: Ken Rockot <rockot@google.com>
Commit-Queue: David Landell <david.landell@xperi.com>
Cr-Commit-Position: refs/heads/main@{#1205690}
This commit is contained in:
David Landell
2023-10-05 07:47:05 +00:00
committed by Chromium LUCI CQ
parent eb5807305c
commit cd266fe875

@ -155,9 +155,10 @@ void ThreadLocalNode::WatchForIncomingTransfers() {
for (;;) {
const IpczResult trap_result =
ipcz.Trap(local_portal_->value(), &conditions, &OnTrapEvent,
reinterpret_cast<uintptr_t>(context.release()), IPCZ_NO_FLAGS,
reinterpret_cast<uintptr_t>(context.get()), IPCZ_NO_FLAGS,
nullptr, nullptr, nullptr);
if (trap_result == IPCZ_RESULT_OK) {
context.release();
return;
}
@ -182,6 +183,7 @@ void ThreadLocalNode::OnTrapEvent(const IpczTrapEvent* event) {
}
weak_node->OnTransferredPortalAvailable();
weak_node->WatchForIncomingTransfers();
}
void ThreadLocalNode::OnTransferredPortalAvailable() {
@ -206,8 +208,6 @@ void ThreadLocalNode::OnTransferredPortalAvailable() {
portal, it->second.release().value(), IPCZ_NO_FLAGS, nullptr);
CHECK_EQ(merge_result, IPCZ_RESULT_OK);
pending_merges_.erase(it);
WatchForIncomingTransfers();
}
} // namespace mojo::internal