Skip to content

Connect EmbeddedChannel when FuzzTesting #1569

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

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions FuzzTesting/Sources/ServerFuzzerLib/ServerFuzzer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public func test(_ start: UnsafeRawPointer, _ count: Int) -> CInt {
let bytes = UnsafeRawBufferPointer(start: start, count: count)

let channel = EmbeddedChannel()
try! channel.connect(to: try! SocketAddress(ipAddress: "127.0.0.1", port: 0)).wait()

defer {
_ = try? channel.finish()
}
Expand Down
11 changes: 8 additions & 3 deletions Sources/GRPC/ConnectionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,14 @@ internal final class ConnectionManager {
state.candidate.whenComplete {
switch $0 {
case let .success(channel):
// In case we do successfully connect, close immediately.
channel.close(mode: .all, promise: nil)
promise.completeWith(channel.closeFuture.recoveringFromUncleanShutdown())
// In case we do successfully connect, close on the next loop tick. When connecting a
// channel NIO will complete the promise for the channel before firing channel active.
// That means we may close and fire inactive before active which HTTP/2 will be unhappy
// about.
self.eventLoop.execute {
channel.close(mode: .all, promise: nil)
promise.completeWith(channel.closeFuture.recoveringFromUncleanShutdown())
}

case .failure:
// We failed to connect, that's fine we still shutdown successfully.
Expand Down
1 change: 1 addition & 0 deletions Tests/GRPCTests/ServerFuzzingRegressionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final class ServerFuzzingRegressionTests: GRPCTestCase {

private func runTest(withInput buffer: ByteBuffer) {
let channel = EmbeddedChannel()
try! channel.connect(to: try! SocketAddress(ipAddress: "127.0.0.1", port: 0)).wait()
defer {
_ = try? channel.finish()
}
Expand Down