[Bug] compressedRegister=true makes broker registration fail: the register body is compressed but the header says it is not

Aperta
#11,425 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@iloveeyjafjalla ci sta già lavorando.

Dal 13/10/2026.

  • #11426 di @iloveeyjafjalla — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
java
Ambito
backend

Direzione di ricerca

The header flag is hardcoded to false at requestHeader.setCompressed(false) in BrokerOuterAPI.java (around line 517), while the body is encoded with encode(compressed). Read RegisterBrokerBody.decode in the namesrv path and the existing RegisterBrokerBodyTest to confirm the expected pairing. Done means the captured register request's header flag matches its body, checked by a BrokerOuterAPITest case. A linked pull request (#11426) already exists, so review or extend it rather than starting a new fix.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Before Creating the Bug Report
  • I found a bug, not just asking a question, which should be created in GitHub Discussions.
  • I have searched the GitHub Issues and GitHub Discussions of this repository and believe that this is not a duplicate.
  • 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:

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).

Lingua principale
Java
Stelle
22.7k
Fork
12k
Merge medio
4g 20h
PR unite (30g)
11

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/rocketmq

Tutte le issue di apache/rocketmq

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.