This is an automated email from the ASF dual-hosted git repository.

shuwenwei pushed a commit to branch supports_subscription
in repository https://gitbox.apache.org/repos/asf/iotdb-client-go.git

commit ef50361a411d6f36009e49ca3d8a550e5e0b2203
Author: shuwenwei <[email protected]>
AuthorDate: Mon Nov 16 17:31:56 2026 +0800

    Fix subscription snapshot completion races
---
 subscription/consumer/pull_flow.go      | 16 +++++++---------
 subscription/consumer/pull_providers.go |  5 ++++-
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/subscription/consumer/pull_flow.go 
b/subscription/consumer/pull_flow.go
index ca5be42..5f076ca 100644
--- a/subscription/consumer/pull_flow.go
+++ b/subscription/consumer/pull_flow.go
@@ -213,9 +213,9 @@ func (c *subscriptionPullConsumer) pollLocked(operationCtx, 
pollCtx context.Cont
                c.mu.Unlock()
        }
        // The caller/lifetime context aborts the entire round. Exhausting only 
the
-       // polling budget instead preserves already complete healthy 
partitions, as
-       // Java does for completed sibling futures. Do not start cleanup RPCs 
after
-       // that budget has expired; undelivered events remain unconfirmed.
+       // polling budget preserves complete healthy partitions, as Java does 
for
+       // completed sibling futures. Keep rollback and empty-delivery ACKs 
tied to
+       // the poll budget; a received termination is handled using 
operationCtx below.
        c.rollbackFlow(pollCtx, failedContexts)
        if pollCtx.Err() == nil && len(emptyContexts) != 0 {
                if err := c.commitContexts(pollCtx, emptyContexts, false); err 
!= nil {
@@ -225,13 +225,11 @@ func (c *subscriptionPullConsumer) 
pollLocked(operationCtx, pollCtx context.Cont
                        }
                }
        }
-       if pollCtx.Err() == nil && len(terminations) != 0 {
+       if operationCtx.Err() == nil && len(terminations) != 0 {
                names := uniqueFlowTopics(terminations)
-               if err := c.changeSubscriptions(pollCtx, names, true); err != 
nil {
-                       if !(operationCtx.Err() == nil && pollCtx.Err() != nil 
&& errors.Is(err, context.DeadlineExceeded)) {
-                               c.rollbackFlow(pollCtx, allContexts)
-                               return nil, err
-                       }
+               if err := c.changeSubscriptions(operationCtx, names, true); err 
!= nil {
+                       c.rollbackFlow(operationCtx, allContexts)
+                       return nil, err
                }
        }
        processed := messages
diff --git a/subscription/consumer/pull_providers.go 
b/subscription/consumer/pull_providers.go
index 31cc355..e3d715c 100644
--- a/subscription/consumer/pull_providers.go
+++ b/subscription/consumer/pull_providers.go
@@ -292,7 +292,10 @@ func (c *subscriptionPullConsumer) providerHeartbeat(ctx 
context.Context, provid
        }
        c.mu.Lock()
        if c.providers[provider.dataNodeID] == provider && 
!provider.connection.Closed() && !c.released && !c.closing {
-               if c.topicRevision == revision {
+               // changeSubscriptions marks an in-flight update with an odd 
revision.
+               // A heartbeat started during that window is not an 
authoritative topic
+               // snapshot, even if no second revision increment has happened 
yet.
+               if c.topicRevision == revision && revision%2 == 0 {
                        c.topics = response.Topics
                } else {
                        response.Unsubscribe = nil

Reply via email to