From fc2851bc48c5ccff419571a7cb41c2da0d4df2f4 Mon Sep 17 00:00:00 2001 From: George Barnett Date: Thu, 3 Jan 2019 14:42:53 +0000 Subject: [PATCH] Upgrade swift-nio to 1.12 --- Package.swift | 2 +- Sources/SwiftGRPCNIO/GRPCChannelHandler.swift | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Package.swift b/Package.swift index 274b9ebb6..4ac744378 100644 --- a/Package.swift +++ b/Package.swift @@ -21,7 +21,7 @@ var packageDependencies: [Package.Dependency] = [ .package(url: "https://github.com/apple/swift-protobuf.git", .upToNextMinor(from: "1.1.1")), .package(url: "https://github.com/kylef/Commander.git", .upToNextMinor(from: "0.8.0")), .package(url: "https://github.com/apple/swift-nio-zlib-support.git", .upToNextMinor(from: "1.0.0")), - .package(url: "https://github.com/apple/swift-nio.git", .upToNextMinor(from: "1.11.0")), + .package(url: "https://github.com/apple/swift-nio.git", .upToNextMinor(from: "1.12.0")), .package(url: "https://github.com/apple/swift-nio-nghttp2-support.git", .upToNextMinor(from: "1.0.0")), .package(url: "https://github.com/apple/swift-nio-http2.git", .revision("dd9339e6310ad8537a271f3ff60a4f3976ca8e4d")) ] diff --git a/Sources/SwiftGRPCNIO/GRPCChannelHandler.swift b/Sources/SwiftGRPCNIO/GRPCChannelHandler.swift index e16879efe..3b8b475eb 100644 --- a/Sources/SwiftGRPCNIO/GRPCChannelHandler.swift +++ b/Sources/SwiftGRPCNIO/GRPCChannelHandler.swift @@ -55,15 +55,20 @@ extension GRPCChannelHandler: ChannelInboundHandler { return } - var responseHeaders = HTTPHeaders() - responseHeaders.add(name: "content-type", value: "application/grpc") - ctx.write(self.wrapOutboundOut(.headers(responseHeaders)), promise: nil) - let codec = callHandler.makeGRPCServerCodec() + let handlerRemoved: EventLoopPromise = ctx.eventLoop.newPromise() + handlerRemoved.futureResult.whenSuccess { handlerWasRemoved in + assert(handlerWasRemoved) + + ctx.pipeline.add(handler: callHandler, after: codec).whenComplete { + var responseHeaders = HTTPHeaders() + responseHeaders.add(name: "content-type", value: "application/grpc") + ctx.write(self.wrapOutboundOut(.headers(responseHeaders)), promise: nil) + } + } + ctx.pipeline.add(handler: codec, after: self) - .then { ctx.pipeline.add(handler: callHandler, after: codec) } - //! FIXME(lukasa): Fix the ordering of this with NIO 1.12 and replace with `remove(, promise:)`. - .whenComplete { _ = ctx.pipeline.remove(handler: self) } + .whenComplete { ctx.pipeline.remove(handler: self, promise: handlerRemoved) } case .message, .end: preconditionFailure("received \(requestPart), should have been removed as a handler at this point")