Aias00 opened a new issue, #4755:
URL: https://github.com/apache/rocketmq-dashboard/issues/4755

   ## Problem
   
   `InstanceService` releases cached RocketMQ clients when an instance endpoint 
or credential reference changes. `MqAdminExtFactory.release(...)` and 
`MqClientPool.release(...)` currently remove the matching cache entry and 
immediately call `shutdown()`.
   
   A request that already obtained the same cached admin, producer, or pull 
consumer can still be executing when the instance update retires it. Immediate 
shutdown can close the client underneath that in-flight action, producing 
avoidable RPC/send/pull failures during a normal configuration update. 
Application shutdown has the same ownership race for actions already admitted 
before the pool is closed.
   
   This lifecycle race is independent of Ops runtime connection settings and 
does not require a default/no-instance connection path.
   
   ## Proposed Design
   
   1. Add a package-private generic `ClientLease<T>` that owns one cached 
client, counts admitted actions, and supports one-way retirement.
   2. `acquire()` succeeds only before retirement; `release()` decrements the 
active count; `retire()` prevents new acquisitions and invokes shutdown exactly 
once when the active count reaches zero.
   3. Store leases in `MqAdminExtFactory` and `MqClientPool` without changing 
cache keys, public method signatures, client construction, authentication 
identity, or provider constructors.
   4. Each execute/send/pull path acquires the current lease before invoking 
the caller action and releases it in `finally`. If it races with a retired 
cache entry, remove that exact lease and retry lookup so the request obtains a 
current client.
   5. Endpoint/credential release removes matching entries and retires them. 
Idle clients close immediately; active clients close after their last action 
completes.
   6. Pool shutdown marks the owner closed before retiring and clearing 
entries, so no new client can be created while already-admitted actions drain.
   
   ## Scope
   
   - `ClientLease`, `MqAdminExtFactory`, `MqClientPool`, and focused lifecycle 
tests only.
   - No Ops connection persistence, default connection routing, 
transport-setting changes, provider constructor changes, deployment files, or 
application configuration.
   - Preserve all existing exception mapping, endpoint normalization, 
authentication isolation, and cache reuse behavior.
   
   ## Acceptance Criteria
   
   - Releasing an idle admin/producer/consumer shuts it down immediately and 
evicts it.
   - Releasing an in-flight client does not call shutdown until the action 
exits.
   - A request arriving after retirement cannot acquire the retired client and 
can create/reuse a replacement.
   - Endpoint-wide and credential-scoped release keep their existing ownership 
boundaries.
   - Shutdown rejects new calls while allowing admitted actions to finish 
before closing their clients.
   - Shutdown is invoked at most once per cached client.
   - All new test method names end with `Test`; focused lifecycle tests, full 
backend tests, Checkstyle, package, and `git diff --check` pass.
   
   ## Direction
   
   The default RocketMQ connection should remain fail-closed and non-editable 
at runtime under the current instance model. This issue extracts only the 
reusable pooled-client lifecycle safety identified during review of #4387.


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