iloveeyjafjalla opened a new issue, #11425:
URL: https://github.com/apache/rocketmq/issues/11425

   ### Before Creating the Bug Report
   
   - [x] I found a bug, not just asking a question, which should be created in 
[GitHub Discussions](https://github.com/apache/rocketmq/discussions).
   - [x] I have searched the [GitHub 
Issues](https://github.com/apache/rocketmq/issues) and [GitHub 
Discussions](https://github.com/apache/rocketmq/discussions) of this repository 
and believe that this is not a duplicate.
   - [x] I have confirmed that this bug belongs to the current repository, not 
other repositories of RocketMQ.
   
   ### Runtime platform environment
   
   OS: any (broker with `compressedRegister=true` in its configuration)
   
   ### RocketMQ version
   
   branch: develop
   Git commit id: a7edeecfb
   
   ### JDK Version
   
   Compiler: Temurin 1.8.0_504 (target 1.8, same as CI)
   
   ### Describe the Bug
   
   `BrokerOuterAPI.registerBrokerAll` compresses the register body when the 
broker has compression enabled, but hardcodes the header flag that tells the 
name server whether the body is compressed:
   
   ```java
   requestHeader.setCompressed(false);                      // 
BrokerOuterAPI.java:517
   ...
   final byte[] body = requestBody.encode(compressed);      // :525 — gzip when 
compressed == true
   ```
   
   `RegisterBrokerBody.encode(boolean compress)` returns a deflate stream 
whenever `compress` is true (`remoting/.../RegisterBrokerBody.java:51-55`), and 
the name server decodes strictly by the flag it receives — 
`RegisterBrokerBody.decode(request.getBody(), requestHeader.isCompressed(), 
brokerVersion)` (`namesrv/.../processor/DefaultRequestProcessor.java:298`) → 
`if (!compressed) { return RegisterBrokerBody.decode(data, 
RegisterBrokerBody.class); }` (`RegisterBrokerBody.java:115-117`), i.e. it 
tries to parse the deflate stream as UTF-8 JSON.
   
   The flag is wired from the configuration: 
`BrokerController.doRegisterBrokerAll` passes 
`this.brokerConfig.isCompressedRegister()` (`BrokerController.java:2169`), and 
registration runs at startup (`registerBrokerAll(true, false, true)`, `:1983`) 
and periodically (`:1998`). The only value that makes the two lines agree is 
the default `false`, which is why this is not visible in normal deployments.
   
   This is a regression from RIP-32: commit `cad0cfcec` ("feature(broker & acl 
& client):[RIP-32]Support Slave Acting Master mode (#3978)") changed 
`requestHeader.setCompressed(compressed)` into 
`requestHeader.setCompressed(false)` while keeping `encode(compressed)`.
   
   ### Steps to Reproduce
   
   1. Set `compressedRegister=true` in `broker.conf` and start the broker with 
a name server.
   2. The broker logs `Failed to register current broker to name server` for 
every name server; on the name server side `RegisterBrokerBody.decode` fails to 
parse the compressed body as JSON (`RemotingCommandException`).
   3. Because `registerBrokerAll` collects results per name server and returns 
an empty list on failure, `handleRegisterBrokerResult` silently does nothing: 
the broker never appears in any route table, and producers/consumers get 
`TOPIC_NOT_EXIST` or route-not-found for every topic hosted by it.
   
   At the unit level the existing harness 
`broker/src/test/java/org/apache/rocketmq/broker/BrokerOuterAPITest.java` 
already registers with `compressed = true` (the 11th argument, line ~197-207) 
but never inspects the request; capturing the `RemotingCommand` passed to 
`nettyRemotingClient.invokeSync` and decoding its body with the header's own 
flag fails deterministically.
   
   ### What Did You Expect to See?
   
   Either the body and the flag describe the same thing — 
`requestHeader.setCompressed(compressed)`, so a compressed body is decompressed 
by the name server as the existing `RegisterBrokerBodyTest` requires (it 
encodes with `encode(true)` and decodes with `decode(..., true, ...)`) — or, if 
the compression feature is being removed, `encode(false)` with the flag left 
off. As it is, the feature is unusable and turning it on breaks the broker's 
registration completely.
   
   ### What Did You See Instead?
   
   `compressedRegister=true` silently prevents the broker from registering at 
all: the name server cannot parse the body, the failures are only logged, and 
the broker looks alive while being absent from every route table.
   
   ### Additional Context
   
   Minimal fix: `requestHeader.setCompressed(compressed)` at 
`BrokerOuterAPI.java:517` (restoring the pre-RIP-32 line), with a test in 
`BrokerOuterAPITest` that captures the register request and asserts the header 
flag describes the captured body.
   
   I will open a PR with that change plus the regression test (red before: the 
captured header says `compressed=false` for a compressed body and decoding it 
with that flag throws; green after: the flag matches and the body decodes).
   


-- 
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]

Reply via email to