Skip to content

Commit c1b54e6

Browse files
committed
Fix how the server handles unknown methods (broken by me in ac7979d, I had forgotten that sending initial metadata is required).
1 parent d3afc45 commit c1b54e6

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

Sources/SwiftGRPC/Core/Handler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public class Handler {
137137
.receiveCloseOnServer,
138138
.sendStatusFromServer(statusCode, statusMessage, trailingMetadata),
139139
.sendMessage(messageBuffer)
140-
]) { operationGroup in
140+
]) { _ in
141141
self.shutdown()
142142
}
143143
try call.perform(operations)

Sources/SwiftGRPC/Core/OperationGroup.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class OperationGroup {
2929
let tag: Int64
3030

3131
/// The call associated with the operation group. Retained while the operations are running.
32+
// FIXME(danielalm): Is this property needed?
3233
private let call: Call
3334

3435
/// An array of operation objects that are passed into the initializer.

Sources/SwiftGRPC/Runtime/ServiceServer.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,22 @@ open class ServiceServer {
6565
+ " calling " + unwrappedMethod
6666
+ " from " + unwrappedCaller
6767
+ " with " + handler.requestMetadata.description)
68-
68+
6969
do {
70-
if try !strongSelf.handleMethod(unwrappedMethod, handler: handler, queue: queue) {
71-
// handle unknown requests
72-
try handler.sendStatus(statusCode: .unimplemented,
73-
statusMessage: "unknown method " + unwrappedMethod,
74-
trailingMetadata: Metadata())
70+
if !(try strongSelf.handleMethod(unwrappedMethod, handler: handler, queue: queue)) {
71+
do {
72+
try handler.call.perform(OperationGroup(
73+
call: handler.call,
74+
operations: [
75+
.sendInitialMetadata(Metadata()),
76+
.receiveCloseOnServer,
77+
.sendStatusFromServer(.unimplemented, "unknown method " + unwrappedMethod, Metadata())
78+
]) { _ in
79+
handler.shutdown()
80+
})
81+
} catch {
82+
print("ServiceServer.start error sending status for unknown method: \(error)")
83+
}
7584
}
7685
} catch {
7786
print("Server error: \(error)")

0 commit comments

Comments
 (0)