Caideyipi opened a new pull request, #18151:
URL: https://github.com/apache/iotdb/pull/18151

   ## Description
   
   This PR fixes subscription consumer lifecycle state ordering for both push 
and pull consumers.
   
   ### Concrete failure scenario
   
   A push or pull subscription consumer calls `open()`. 
`AbstractSubscriptionConsumer.open()` opens providers and submits the heartbeat 
and endpoint-sync workers before the push/pull subclass flips its own 
`isClosed` flag to `false`. If either scheduled worker runs immediately, the 
worker dispatches to the subclass `isClosed()` override, observes the consumer 
as closed, cancels its own future, and leaves the already-open consumer without 
heartbeat or endpoint synchronization.
   
   A symmetric close path can also leak providers: push/pull `close()` 
previously called the base close before marking the subclass closed. During 
that window, an endpoint-sync task can still treat the consumer as open and 
reopen subscription providers after close has begun.
   
   ### Fix
   
   - Mark push/pull consumers open before invoking the base open path, and roll 
the subclass state back if open fails.
   - Mark push/pull consumers closed before closing providers in the base close 
path.
   - Re-check the consumer closed state after acquiring the provider write lock 
in heartbeat and endpoint sync.
   - Add focused lifecycle unit tests for push and pull consumers.
   
   ### Tests
   
   - `mvn spotless:apply -pl iotdb-client/subscription`
   - `mvn -pl iotdb-client/subscription 
-Dtest=SubscriptionConsumerLifecycleTest test`
   - `mvn -pl iotdb-client/subscription test`
   - `mvn -pl iotdb-client/subscription -P with-zh-locale -DskipTests 
test-compile`
   
   <hr>
   
   This PR has:
   - [x] been self-reviewed.
       - [x] concurrent read
       - [x] concurrent write
       - [x] concurrent read and write
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] added Javadocs for most classes and all non-trivial methods.
   - [ ] added or updated version, __license__, or notice information
   - [ ] added comments explaining the "why" and the intent of the code 
wherever would not be obvious for an unfamiliar reader.
   - [x] added unit tests or modified existing tests to cover new code paths, 
ensuring the threshold for code coverage.
   - [ ] added integration tests.
   - [ ] been tested in a test IoTDB cluster.
   
   <hr>
   
   ##### Key changed/added classes (or packages if there are too many classes) 
in this PR
   
   - 
`org.apache.iotdb.session.subscription.consumer.base.AbstractSubscriptionPushConsumer`
   - 
`org.apache.iotdb.session.subscription.consumer.base.AbstractSubscriptionPullConsumer`
   - 
`org.apache.iotdb.session.subscription.consumer.base.AbstractSubscriptionProviders`
   - 
`org.apache.iotdb.session.subscription.consumer.base.SubscriptionConsumerLifecycleTest`


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