Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix potential hang with concurrent reads or concurrent writes
Fot two threads, T1 and T2, both writing to the same connection, the sequence of events for a failure is as follows (line numbers all pre this commit): - T1 obtains the write semaphore (L1366) - T1 creates an OperationState and sets writeOperation (L1390) - the async write for T1 completes and the completion handler is called - T1's completion handler releases the semaphore (L1046) - T2 obtains the write semaphore (L1366) - T2 creates an OperationState and sets writeOperation (L1390) - T1's completion handler clears writeOperation (L1050) - the async write for T2 does not complete and the socket is added to the Poller - The Poller signals the socket is ready for write - The Poller finds writeOperation is null so performs a normal dispatch for write - The async write times out as it never receives the notification from the Poller The fix is to swap the order of clearing writeOperation and releasing the semaphore.
- Loading branch information