If a Dispatch I/O instance has pending dispatch_io_read, the dispatch_io_close waits for the dispatch_io_read to be completed before releasing resources. However, [EDOSocketChannel -receiveDataWithHandler:] does two consecutive dispatch_io_read, so the second dispatch_io_read may corrupt dispatch_io_close when TSAN is enabled.
Proposed Fix
In [EDOSocketChannel -receiveDataWithHandler:], before performing the second dispatch_io_read, it first checks if the Dispatch I/O is still valid.
Fix part of the TSAN flakiness of ChannelTests.
How does the flakiness happen?
If a Dispatch I/O instance has pending dispatch_io_read, the dispatch_io_close waits for the dispatch_io_read to be completed before releasing resources. However,
[EDOSocketChannel -receiveDataWithHandler:]
does two consecutive dispatch_io_read, so the second dispatch_io_read may corrupt dispatch_io_close when TSAN is enabled.Proposed Fix
In
[EDOSocketChannel -receiveDataWithHandler:]
, before performing the second dispatch_io_read, it first checks if the Dispatch I/O is still valid.