-
Notifications
You must be signed in to change notification settings - Fork 651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle bind failures when running NIO in a tight sandbox #2616
base: main
Are you sure you want to change the base?
Changes from all commits
d269c1c
cd40dee
3b33ceb
7f03ce8
e13a5b2
a4863a8
5f1d8c4
f18ea23
85bfd59
6d777bf
57266e9
ee340f1
1e9b010
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -322,6 +322,48 @@ final class SALChannelTest: XCTestCase, SALTest { | |
} | ||
}.salWait()) | ||
} | ||
|
||
func testBindFailureClosesChannel() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test isn't specific enough: it continues to pass even with the new The same code appears to be present in the server bootstrap. Can we try to nail down where the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, I will be taking a closer look at this over the weekend! |
||
guard let channel = try? self.makeSocketChannel() else { | ||
XCTFail("couldn't make a channel") | ||
return | ||
} | ||
let localAddress = try! SocketAddress(ipAddress: "1.2.3.4", port: 5) | ||
let serverAddress = try! SocketAddress(ipAddress: "9.8.7.6", port: 5) | ||
|
||
XCTAssertThrowsError(try channel.eventLoop.runSAL(syscallAssertions: { | ||
try self.assertSetOption(expectedLevel: .tcp, expectedOption: .tcp_nodelay) { value in | ||
return (value as? SocketOptionValue) == 1 | ||
} | ||
try self.assertSetOption(expectedLevel: .socket, expectedOption: .so_reuseaddr) { value in | ||
return (value as? SocketOptionValue) == 1 | ||
} | ||
try self.assertBind(expectedAddress: localAddress, errorReturn: IOError(errnoCode: EPERM, reason: "bind")) | ||
try self.assertDeregister { selectable in | ||
return true | ||
} | ||
try self.assertClose(expectedFD: .max) | ||
|
||
}) { | ||
ClientBootstrap(group: channel.eventLoop) | ||
.channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) | ||
.channelOption(ChannelOptions.autoRead, value: false) | ||
.bind(to: localAddress) | ||
.testOnly_connect(injectedChannel: channel, to: serverAddress) | ||
.flatMapError { error in | ||
guard let ioError = error as? IOError else { | ||
XCTFail("Expected IOError, got \(error)") | ||
return channel.eventLoop.makeFailedFuture(error) | ||
} | ||
XCTAssertEqual(ioError.errnoCode, EPERM, "Expected EPERM error code") | ||
XCTAssertTrue(!channel.isActive, "Channel should be closed") | ||
return channel.eventLoop.makeFailedFuture(error) | ||
} | ||
.flatMap { channel in | ||
channel.close() | ||
} | ||
}.salWait()) | ||
} | ||
|
||
func testAcceptingInboundConnections() throws { | ||
final class ConnectionRecorder: ChannelInboundHandler { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon bind failing, the
lifecycleManager
seems to remain in thepreRegistered
state. thus we are transiting to theclosed
state here.