Skip to content

Commit

Permalink
Second improvement of TSAN flakiness on channel tests.
Browse files Browse the repository at this point in the history
The flakiness rate is higher when cleanup handlers of multiple dispatch IO are invoked at the same time on the different queues. Consequently, let's use a single serial queue to close socket for EDOSocketChannel.

PiperOrigin-RevId: 326268100
  • Loading branch information
AlbertWang0116 authored and mobile-devx-github-bot committed Aug 12, 2020
1 parent 1e41b4c commit b6ac886
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Channel/Sources/EDOSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,28 @@ static void edo_RunHandlerWithErrorInQueueWithBlock(int code, dispatch_queue_t q

#pragma mark - EDOSocket implementation

@interface EDOSocket ()

/** The global serial queue for handling dispatch I/O's cleanup handler and closing socket. */
@property(class, atomic, readonly) dispatch_queue_t closeSocketQueue;

@end

@implementation EDOSocket {
dispatch_fd_t _socket;
}

@dynamic valid;

+ (dispatch_queue_t)closeSocketQueue {
static dispatch_queue_t closeSocketQueue;
static dispatch_once_t once_token;
dispatch_once(&once_token, ^{
closeSocketQueue = dispatch_queue_create("com.google.edo.CloseSocket", DISPATCH_QUEUE_SERIAL);
});
return closeSocketQueue;
}

+ (nullable instancetype)socketWithTCPPort:(UInt16)port
queue:(dispatch_queue_t _Nullable)queue
error:(NSError *_Nullable *_Nullable)error {
Expand Down Expand Up @@ -125,7 +141,7 @@ - (nullable dispatch_io_t)releaseAsDispatchIO {
return NULL;
}

dispatch_queue_t queue = dispatch_queue_create("com.google.edo.SocketIO", DISPATCH_QUEUE_SERIAL);
dispatch_queue_t queue = [self class].closeSocketQueue;
dispatch_io_t channel = dispatch_io_create(DISPATCH_IO_STREAM, socket, queue, ^(int error) {
if (error) {
NSLog(@"Error (%d) when closing dispatch channel.", error);
Expand Down

0 comments on commit b6ac886

Please sign in to comment.