Skip to content

Commit ef061fd

Browse files
committed
Resolve the transcoding head promise when a unary call ends without a message.
Motivation: Transcoding defers the HTTP head until the response body is known, so writeHead returns a promise resolved by writeUnaryMessage. A unary call that ends without ever writing a message never resolves it and leaves the caller waiting. Changes: Resolve the head promise from writeEnd when it is still pending. Fix the indentation of the SSE branch.
1 parent 8f08bda commit ef061fd

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

vertx-grpc-transcoding/src/main/java/io/vertx/grpc/transcoding/impl/TranscodingGrpcOutboundStream.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ private Future<Void> writeUnaryMessage(Buffer payload) {
133133
httpResponse.setStatusCode(500).end();
134134
res = context.failedFuture(e);
135135
}
136-
if (head != null) {
137-
res.onComplete(head);
136+
Promise<Void> h = head;
137+
if (h != null) {
138+
head = null;
139+
res.onComplete(h);
138140
}
139141
return res;
140142
}
@@ -158,7 +160,7 @@ private Future<Void> writeStreamingMessage(Buffer payload) {
158160
chunk = Buffer.buffer(transcoded.length() + NEWLINE.length()).appendBuffer(transcoded).appendBuffer(NEWLINE);
159161
break;
160162
}
161-
case SSE: {
163+
case SSE: {
162164
chunk = Buffer.buffer(SSE_PREFIX.length() + transcoded.length() + SSE_SUFFIX.length())
163165
.appendBuffer(SSE_PREFIX).appendBuffer(transcoded).appendBuffer(SSE_SUFFIX);
164166
break;
@@ -185,6 +187,14 @@ public Future<Void> writeEnd() {
185187
if (status != GrpcStatus.OK) {
186188
httpResponse.setStatusCode(GrpcTranscodingError.fromHttp2Code(status.code).getHttpStatusCode());
187189
}
188-
return super.writeEnd();
190+
Future<Void> res = super.writeEnd();
191+
// A unary call can end without ever writing a message, e.g. a failed call: the head promise
192+
// is only resolved by writeUnaryMessage, so resolve it here instead of leaving it pending.
193+
Promise<Void> h = head;
194+
if (h != null) {
195+
head = null;
196+
res.onComplete(h);
197+
}
198+
return res;
189199
}
190200
}

0 commit comments

Comments
 (0)