-
Notifications
You must be signed in to change notification settings - Fork 8.9k
feature: support http2 #7451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: support http2 #7451
Conversation
core/src/main/java/org/apache/seata/core/rpc/netty/http/Http2HttpHandler.java
Outdated
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 2.x #7451 +/- ##
============================================
+ Coverage 60.34% 60.37% +0.03%
Complexity 658 658
============================================
Files 1281 1284 +3
Lines 48308 48465 +157
Branches 5676 5694 +18
============================================
+ Hits 29150 29263 +113
- Misses 16553 16585 +32
- Partials 2605 2617 +12
🚀 New features to boost your workflow:
|
core/src/main/java/org/apache/seata/core/rpc/netty/http/HttpDispatchHandler.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/apache/seata/core/rpc/netty/http/Http2HttpHandlerTest.java
Outdated
Show resolved
Hide resolved
YongGoose
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks well written overall!
However, I noticed that there are quite a few comments written in Chinese in the test code. It would be great if you could update them to English :)
Also, for BaseHttpChannelHandler, it might be helpful to add some information about the role of this class, and which classes extend it.
Thank you for your work, always 👍🏻
| ChannelInboundHandlerAdapter finalExceptionHandler = new ChannelInboundHandlerAdapter() { | ||
| @Override | ||
| public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { | ||
| if (cause instanceof java.io.IOException) { | ||
| LOGGER.trace("Connection closed by client: {}", cause.getMessage()); | ||
| } else { | ||
| LOGGER.error("Exception caught in HTTP pipeline: ", cause); | ||
| } | ||
| ctx.close(); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it okay not to override methods like channelInactive and channelUnregistered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it okay not to override methods like
channelInactiveandchannelUnregistered?
Since most HTTP connections are short-lived, if you do not override the exceptionCaught method, a large number of unexpected connection closed exceptions will be output. For example, if you use the curl command to simulate a request, you will encounter such exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.\curl.exe -i -X POST 127.0.0.1:8091/health --http2
23:23:16.110 ERROR --- [tyServerNIOWorker_1_10_16] [protocol.detector.HttpDetector] [ exceptionCaught] [] : Connection closed by client:
core/src/main/java/org/apache/seata/core/rpc/netty/http/Http2HttpHandler.java
Show resolved
Hide resolved
core/src/main/java/org/apache/seata/core/rpc/netty/http/Http2HttpHandler.java
Show resolved
Hide resolved
…ttpHandlerTest.java Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds HTTP/2 protocol support to Seata server, enabling HTTP/1→HTTP/2 upgrade (excluding gRPC) and unified context handling.
- Introduces
Http2HttpHandler,BaseHttpChannelHandler, and enhanced protocol detectors (HttpDetector,Http2Detector). - Refactors
HttpDispatchHandlerto use genericHttpContext<T>and removes its custom thread-pool setup. - Updates cluster‐watch APIs to parameterize
HttpContextand adjust notification logic.
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| server/src/main/java/org/apache/seata/server/controller/ClusterController.java | Parameterized HttpContext to HttpContext<?> |
| server/src/main/java/org/apache/seata/server/cluster/manager/ClusterWatcherManager.java | Restricted watcher queues to Watcher<HttpContext> and refined response logic |
| namingserver/src/main/java/org/apache/seata/namingserver/manager/ClusterWatcherManager.java | Reordered imports (no functional change) |
| core/src/test/java/org/apache/seata/core/rpc/netty/http/Http2HttpHandlerTest.java | Added comprehensive HTTP/2 handler tests |
| core/src/main/java/org/apache/seata/core/rpc/netty/http/SimpleHttp2Request.java | New DTO for encapsulating HTTP/2 requests |
| core/src/main/java/org/apache/seata/core/rpc/netty/http/HttpDispatchHandler.java | Switched to BaseHttpChannelHandler and simplified error handling |
| core/src/main/java/org/apache/seata/core/rpc/netty/http/Http2HttpHandler.java | New handler for HTTP/2 frames and request dispatching |
| core/src/main/java/org/apache/seata/core/rpc/netty/http/BaseHttpChannelHandler.java | Extracted shared HTTP logic (mapper, thread pool) |
| core/src/main/java/org/apache/seata/core/protocol/detector/HttpDetector.java | Enhanced detector to support HTTP/1→HTTP/2 upgrade |
| core/src/main/java/org/apache/seata/core/protocol/detector/Http2Detector.java | Routes gRPC vs non-gRPC streams after HTTP/2 preface |
| common/src/main/java/org/apache/seata/common/rpc/http/HttpContext.java | Refactored to generic HttpContext<T> with version info |
| changes/zh-cn/2.x.md & changes/en-us/2.x.md | Updated changelogs to include the HTTP/2 feature |
Comments suppressed due to low confidence (1)
core/src/main/java/org/apache/seata/core/protocol/detector/HttpDetector.java:104
- The magic number
1048576is repeated here and in theHttpObjectAggregatorinstantiation. Extract it into a named constant (e.g.,MAX_CONTENT_LENGTH) to improve readability and maintainability.
};
server/src/main/java/org/apache/seata/server/cluster/manager/ClusterWatcherManager.java
Show resolved
Hide resolved
core/src/main/java/org/apache/seata/core/rpc/netty/http/HttpDispatchHandler.java
Show resolved
Hide resolved
core/src/main/java/org/apache/seata/core/protocol/detector/Http2Detector.java
Outdated
Show resolved
Hide resolved
| } | ||
| })); | ||
| } else { | ||
| return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn’t passing null cause a NullPointerException?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YongGoose
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM

Ⅰ. Describe what this PR did
Supports the HTTP/2 protocol and allows upgrading from HTTP/1 to HTTP/2, but only when the content-type is not grpc.

Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews