Skip to content

Commit

Permalink
fix one more register/bind race (#379)
Browse files Browse the repository at this point in the history
Motivation:

On Linux registration without bind/connect leads to `EPOLLHUP` and in
tests we often hit that race. This fixes one more instance of that.

Modifications:

Make sure the bind happens before we enter the selector.

Result:

more stable tests, fixes #378.
  • Loading branch information
weissi authored and Lukasa committed May 2, 2018
1 parent 2b9469b commit 8063cd3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Tests/NIOTests/SocketChannelTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,13 @@ public class SocketChannelTest : XCTestCase {
let serverChannel = try ServerSocketChannel(serverSocket: socket, eventLoop: group.next() as! SelectableEventLoop, group: group)
let promise: EventLoopPromise<IOError> = serverChannel.eventLoop.newPromise()

XCTAssertNoThrow(try serverChannel.pipeline.add(handler: AcceptHandler(promise)).then {
serverChannel.register()
}.then {
serverChannel.bind(to: try! SocketAddress(ipAddress: "127.0.0.1", port: 0))
}.wait())
XCTAssertNoThrow(try serverChannel.eventLoop.submit {
serverChannel.pipeline.add(handler: AcceptHandler(promise)).then {
serverChannel.register()
}.then {
serverChannel.bind(to: try! SocketAddress(ipAddress: "127.0.0.1", port: 0))
}
}.wait().wait() as Void)

XCTAssertEqual(active, try serverChannel.eventLoop.submit {
serverChannel.readable()
Expand Down

0 comments on commit 8063cd3

Please sign in to comment.