RLDE26 opened a new pull request, #11606:
URL: https://github.com/apache/rocketmq/pull/11606

   ### Which Issue(s) This PR Fixes
   
   - Fixes #11602
   
   ### Brief Description
   
   **1. Config file streams** (`ControllerStartup`, `NamesrvStartup`)
   `in.close()` sat at the end of a straight-line block. Any exception in 
`properties.load()` or the following `properties2Object()` calls skipped it, 
leaking the file handle. Both are now wrapped in try-with-resources.
   
   **2. TLS key material** (`TlsHelper`)
   The certificate and private key streams were created inline as arguments to 
`keyManager(...)` / `forServer(...)`, so no reference survived the call and 
they were never closed. Both are now declared inside a try-with-resources 
block. Note that `decryptPrivateKey()` also returns an `InputStream`, so up to 
four streams leaked, not two.
   
   `keyManager(InputStream, InputStream, String)` consumes both streams 
synchronously (`SslContext.toX509Certificates` / `toPrivateKey`) and 
`SslContextBuilder` keeps no `InputStream` field, so closing them once 
`keyManager` returns is safe. This is one step earlier than the Javadoc wording 
("close after `build()` has been called"); the reasoning rests on the method 
body, not on undocumented state.
   
   **3. RocksIterator** (`RocksDBConfigToJsonCommand`)
   The iterator was created before the `try`, so if `iterator()` itself threw, 
the `finally { shutdown(path); }` never ran. Moving the declaration into the 
resource block fixes that, and `try (R) B finally F` guarantees the iterator is 
closed before the DB is shut down.
   
   **4. Zstd stream** (`ZstdCompressor`)
   `outputStream.close()` inside the `try` was skipped when `write()` threw. It 
is now managed by try-with-resources. `toByteArray()` had to move out of the 
`try` block: `ZstdOutputStream.close()` is what flushes the frame, so reading 
the array before the block exits returns a truncated result. The old `finally` 
block also closed the `ByteArrayOutputStream`, whose `close()` is a no-op in 
the JDK and holds no native resource, so it is dropped.
   
   **5. RocksDB shutdown sequence** (`AbstractRocksDBStorage#shutdown`)
   The release steps run in a straight line, so a failure in one call jumped to 
the trailing `catch` and skipped `db.closeE()`. The three calls that can throw 
— `awaitTermination` (`InterruptedException`), `pauseBackgroundWork` 
(`RocksDBException`) and `preShutdown()` (abstract, reaches JNI in one 
subclass) — are now wrapped in local try-catch blocks, so the handles, the 
options and `db.closeE()` are always reached.
   
   
   ### How Did You Test This Change?
   
   - `mvn -pl 
common,remoting,client,srvutil,proto,auth,tools,controller,namesrv -am 
-DskipTests compile` — all modules SUCCESS, including checkstyle (bound to the 
`validate` phase).
   - `mvn -pl common -Dtest=ZstdCompressorTest test` — 5 tests, 0 failures.
   - Negative check on the Zstd change: moving `toByteArray()` back inside the 
`try` block makes `testCompressAndDecompress` fail with `Read error or 
truncated stream`, confirming the ordering requirement is actually covered by 
that test.
   
   


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