Copilot commented on code in PR #16585:
URL: https://github.com/apache/dubbo/pull/16585#discussion_r4584167466
##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/h12/http2/GenericHttp2ServerTransportListener.java:
##########
@@ -186,6 +199,56 @@ protected void onMetadataCompletion(Http2Header metadata) {
}
}
+ @Override
+ protected Http2InputMessage onDataReceived(Http2InputMessage message) {
+ PendingInput input = newPendingInput(message);
+ synchronized (inputLock) {
+ pendingInputs.add(input);
+ if (inputClosed && processingInputs == 0) {
+ closeInput(input);
+ }
+ }
+ return new Http2InputMessageFrame(message.id(), input,
message.isEndStream());
+ }
+
+ protected PendingInput newPendingInput(Http2InputMessage message) {
+ return new PendingInput(message);
+ }
+
+ @Override
+ protected void doOnData(Http2InputMessage message) {
+ PendingInput input = (PendingInput) message.getBody();
+ synchronized (inputLock) {
+ if (inputClosed || input.closed.get()) {
+ closeInput(input);
+ return;
+ }
+ processingInputs++;
+ }
+ try {
+ super.doOnData(message);
+ } finally {
+ synchronized (inputLock) {
+ if (--processingInputs == 0 && inputClosed) {
+ closePendingInputs();
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void onDataMessage(Http2InputMessage message,
HttpMessageListener listener) {
+ synchronized (inputLock) {
+ if (inputClosed) {
+ return;
+ }
+ // The decoder owns accepted input, including any bytes buffered
for later requests.
+ // Only inputs that have not crossed this boundary belong to the
transport registry.
+ pendingInputs.remove((PendingInput) message.getBody());
+ }
+ super.onDataMessage(message, listener);
Review Comment:
The pending-input registry removes ownership *before* calling
`super.onDataMessage(...)` (which invokes `listener.onMessage(...)`). If
`listener.onMessage(...)` throws, registry ownership has already ended,
contradicting the comment (“until the message listener accepts the body”) and
potentially preventing transport-driven cleanup from running for that input. A
safer pattern is to remove from `pendingInputs` only after
`super.onDataMessage(...)` returns successfully, or remove inside a try block
and re-add/close in a catch/finally when delivery fails.
##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/h12/AbstractServerTransportListener.java:
##########
@@ -158,32 +159,48 @@ protected void onMetadataError(HEADER metadata, Throwable
throwable) {
protected void initializeAltSvc(URL url) {}
@Override
- public final void onData(MESSAGE message) {
+ public final void onData(MESSAGE input) {
+ MESSAGE message = onDataReceived(input);
if (executor == null) {
onDataFinally(message);
return;
}
- executor.execute(() -> {
- try {
- doOnData(message);
- } catch (Throwable t) {
- logError(t);
- onError(message, t);
- } finally {
- onDataFinally(message);
- }
- });
+ try {
+ executor.execute(() -> {
+ try {
+ doOnData(message);
+ } catch (Throwable t) {
+ logError(t);
+ onError(message, t);
+ } finally {
+ onDataFinally(message);
+ }
+ });
+ } catch (RejectedExecutionException e) {
+ onError(message, e);
Review Comment:
`onDataFinally(message)` is no longer guaranteed to run when
`executor.execute(...)` throws `RejectedExecutionException`. If `onDataFinally`
performs required cleanup/bookkeeping (even in subclasses), this can leak
resources or leave state inconsistent. Consider invoking
`onDataFinally(message)` in the `catch` path as well (typically in a `finally`
around submission, or explicitly after `onError(message, e)`), so every
`onDataReceived(...)` message gets a matching `onDataFinally(...)`.
##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/h12/http2/GenericHttp2ServerTransportListener.java:
##########
@@ -229,9 +293,54 @@ protected final Http2ServerChannelObserver
getResponseObserver() {
@Override
public void close() {
+ closeInputs();
responseObserver.close();
}
+ private void closeInputs() {
+ synchronized (inputLock) {
+ inputClosed = true;
+ if (processingInputs == 0) {
+ closePendingInputs();
+ }
+ }
+ }
+
+ private void closePendingInputs() {
+ // An already-started callback may still be preparing its DATA
message. Defer
+ // pre-delivery cleanup until it returns; accepted input belongs to
the decoder.
+ for (PendingInput input : pendingInputs) {
+ closeInput(input);
+ }
+ }
Review Comment:
`closePendingInputs()` (and the `inputClosed && processingInputs == 0` path
in `onDataReceived`) can end up closing request bodies while holding
`inputLock`. Since `message.close()` can perform arbitrary work (and may
involve callbacks), this risks lock contention or deadlock and can stall
concurrent DATA processing. Consider snapshotting `pendingInputs` under
`inputLock` (e.g., copy to a local list) and performing the actual
`closeInput(...)` calls outside the synchronized section; keep the lock scope
limited to state transitions and snapshot creation.
##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/websocket/DefaultWebSocketServerTransportListener.java:
##########
@@ -99,6 +99,25 @@ protected void onDataCompletion(Http2InputMessage message) {
super.onDataCompletion(message);
}
+ @Override
+ protected PendingInput newPendingInput(Http2InputMessage message) {
+ return message.getBody() instanceof
org.apache.dubbo.remoting.websocket.FinalFragment
+ ? new PendingFragmentInput(message)
+ : super.newPendingInput(message);
+ }
+
+ private final class PendingFragmentInput extends PendingInput
+ implements org.apache.dubbo.remoting.websocket.FinalFragment {
+ private PendingFragmentInput(Http2InputMessage message) {
+ super(message);
+ }
+
+ @Override
+ public boolean isFinalFragment() {
+ return ((org.apache.dubbo.remoting.websocket.FinalFragment)
in).isFinalFragment();
+ }
+ }
Review Comment:
The repeated fully-qualified
`org.apache.dubbo.remoting.websocket.FinalFragment` references make this block
harder to read and maintain. Prefer a single import (or a local alias via
import) and use the simple type name in the `instanceof`, `implements`, and
cast sites.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]