729057ab8c
Previously, Looper internally kept track of the requests to add fds using the fd value itself. It used an internal sequence number associated with each request to add a callback to avoid a situation where a callback is unexpectedly called. However, since it used the fd value rather than the sequence number to register events into epoll, there was still a way where unintended hangups could occur. This exact sequence of events caused unintended behavior in Looper: - An fd (FD) is added to the looper. - Looper registers FD into epoll using its FD number. - FD is closed. - A hangup event arrives from epoll_wait while the Looper is polling. Looper is waiting for the lock to process the callback for FD, because it is blocked by: - A new fd is created and added to the looper. Since the lowest number fd is reused, this new fd has the same value as FD. - The poll request for Looper is now unblocked, so it looks up the callback associated with FD to process the hangup. - Since FD is already associated with the new callback, the new callback is called unintentionally. This CL uses the sequence number to register fds into epoll. That way, when we get a hangup from epoll that is associated with a sequence number, there is no way an unexpected callback will called. This CL also adds a test to verify this behavior. Due to the nondeterministic nature of this multi-thread scenario, the test verifies this scenario repeatedly. Without the fix in Looper, the test is flaky, but should never fail after the fix. Bug: 195020232 Bug: 189135695 Test: atest libutils_test --rerun-until-failure Ignore-AOSP-First: Topic CL aosp/1799831 has a merge conflict with internal master, resolved in ag/15613419. Change-Id: Ib4edab7f2407adaef6a1708b29bc52634f25dbb6 |
||
---|---|---|
.. | ||
AndroidThreads.h | ||
Atomic.h | ||
BitSet.h | ||
ByteOrder.h | ||
CallStack.h | ||
Compat.h | ||
Condition.h | ||
Debug.h | ||
Endian.h | ||
Errors.h | ||
FastStrcmp.h | ||
FileMap.h | ||
Flattenable.h | ||
Functor.h | ||
JenkinsHash.h | ||
KeyedVector.h | ||
LightRefBase.h | ||
List.h | ||
Log.h | ||
Looper.h | ||
LruCache.h | ||
misc.h | ||
Mutex.h | ||
NativeHandle.h | ||
Printer.h | ||
ProcessCallStack.h | ||
RefBase.h | ||
RWLock.h | ||
Singleton.h | ||
SortedVector.h | ||
StopWatch.h | ||
String8.h | ||
String16.h | ||
StrongPointer.h | ||
SystemClock.h | ||
Thread.h | ||
ThreadDefs.h | ||
threads.h | ||
Timers.h | ||
Tokenizer.h | ||
Trace.h | ||
TypeHelpers.h | ||
Unicode.h | ||
Vector.h | ||
VectorImpl.h |