hangc0276 commented on code in PR #4802:
URL: https://github.com/apache/bookkeeper/pull/4802#discussion_r4762981014
##########
stream/storage/impl/src/main/java/org/apache/bookkeeper/stream/storage/impl/routing/RoutingHeaderProxyInterceptor.java:
##########
@@ -337,15 +337,25 @@ private <ReqT, TableReqT> ReqT interceptMessage(
if (null == descriptor) {
return message;
} else {
+ byte[] requestBytes = null;
try {
- return interceptTableRequest(method, descriptor, message, sid,
rid, rk);
+ if (message.getClass() == descriptor.getClz()) {
+ return interceptTableRequest(method, descriptor, message,
sid, rid, rk);
+ } else {
+ InputStream is =
method.getRequestMarshaller().stream(message);
+ requestBytes = is.readAllBytes();
+ return interceptTableRequest(method, descriptor,
requestBytes, sid, rid, rk);
+ }
} catch (Throwable t) {
log.error()
.attr("streamId", sid)
.attr("rangeId", rid)
.attr("routingKey", Hex.encodeHexString(rk))
.exception(t)
.log("Failed to intercept table request");
+ if (null != requestBytes) {
+ return method.getRequestMarshaller().parse(new
ByteArrayInputStream(requestBytes));
Review Comment:
**Important (traced, not reproduced).** This fixes the consumed-stream
symptom but I could not show it fixes the flake. The reported failure (`Invalid
unknown tag type: 4` in `TxnRequest.parseFrom`) happens on the very bytes
retained here, so forwarding them only helps if the interceptor's parse failed
spuriously on valid bytes. If the bytes are really malformed (for example the
buffer is released or reused before the proxy reads it), the backend gets the
same garbage and fails the same way. I tried to provoke a spurious parse
failure with 32,000 valid requests from 8 threads and got none.
Also, on this path the request now reaches the backend without the
routing-header rewrite. The old fallback happened to fail the call (empty
body); this one can deliver an un-rewritten request. That fail-open behaviour
matches the existing `return message`, but it is unproven that the backend
accepts such a request.
Suggestion: log the payload length and the first bytes in the failure log,
so the real cause becomes visible, and show repeated
`TableClientTest.testTableAPIServerSideRouting` runs with and without the
change.
##########
stream/storage/impl/src/main/java/org/apache/bookkeeper/stream/storage/impl/routing/RoutingHeaderProxyInterceptor.java:
##########
@@ -363,9 +373,8 @@ private <ReqT, TableReqT> ReqT interceptTableRequest(
if (message.getClass() == interceptor.getClz()) {
request = (TableReqT) message;
} else {
- InputStream is = method.getRequestMarshaller().stream(message);
- byte[] bytes = is.readAllBytes();
- request = interceptor.getParser().parseFrom(bytes);
+ return interceptTableRequest(method, interceptor,
Review Comment:
**Nit (traced).** After this PR `interceptMessage` calls this overload only
when `message.getClass() == descriptor.getClz()`. So this `else` branch can no
longer be reached from there, and the `message.getClass() ==
interceptor.getClz()` check is now repeated three times in the method. Suggest
dropping the branch (and the second class check below it).
##########
stream/storage/impl/src/main/java/org/apache/bookkeeper/stream/storage/impl/routing/RoutingHeaderProxyInterceptor.java:
##########
@@ -337,15 +337,25 @@ private <ReqT, TableReqT> ReqT interceptMessage(
if (null == descriptor) {
return message;
} else {
+ byte[] requestBytes = null;
try {
- return interceptTableRequest(method, descriptor, message, sid,
rid, rk);
+ if (message.getClass() == descriptor.getClz()) {
+ return interceptTableRequest(method, descriptor, message,
sid, rid, rk);
+ } else {
+ InputStream is =
method.getRequestMarshaller().stream(message);
+ requestBytes = is.readAllBytes();
Review Comment:
**Nit (reproduced).** If `readAllBytes()` throws mid-read, `requestBytes` is
still `null`, so the catch block returns the original `message`, a
half-consumed stream, to the backend. Test: a stream that yields 2 bytes and
then throws `IOException`. The test asserts that the call fails or the stream
is not forwarded, and it fails with "a request whose stream failed mid-read was
forwarded to the backend". The control (healthy stream) passes.
Impact is low, since this stream throws again when gRPC reads it. A stream
that recovers from a transient error could instead send a truncated request.
Suggestion: rethrow when reading the bytes fails, so the call fails instead of
forwarding a partial stream.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]