Skip to content

Fix repeated RPC dispatch reusing a released FragmentInstanceContext (NPE)#17794

Merged
JackieTien97 merged 3 commits into
masterfrom
ty/fixOpt
Jun 1, 2026
Merged

Fix repeated RPC dispatch reusing a released FragmentInstanceContext (NPE)#17794
JackieTien97 merged 3 commits into
masterfrom
ty/fixOpt

Conversation

@JackieTien97

Copy link
Copy Markdown
Contributor

Problem

Per the root-cause analysis: FragmentInstanceDispatcherImpl.dispatchRemote retries the same FragmentInstance once after a TException. A TException only means the client didn't receive the response — the server may have already executed the FI. After the first execution finishes it runs releaseResource() (dataRegion = null) but its FragmentInstanceContext stays cached in FragmentInstanceManager.instanceContext (~5 min) while instanceExecution is removed. The retry hits instanceContext.computeIfAbsent, reuses the released context, and a fresh (ALIVE) driver dereferences the null dataRegion in init()NPE. The single-execution guards don't help because this is cross-execution reuse.

Changes

  • TSStatusCode: add REPEATED_RPC_CALL(723) (intentionally not in NEED_RETRY).
  • FragmentInstanceManager (data + schema paths): when instanceContext.computeIfAbsent would reuse an existing context for the same instanceId, throw IoTDBRuntimeException(REPEATED_RPC_CALL) before the planning try block — so it propagates up cleanly without invoking clearFIRelatedResources/createFailedInstanceInfo on the first execution's cached resources.
  • RegionReadExecutor: in both catch blocks, carry an IoTDBRuntimeException's status code back so REPEATED_RPC_CALL reaches the dispatcher (instead of being downgraded to EXECUTE_STATEMENT_ERROR); needRetryHelper keeps it non-retryable.
  • FragmentInstanceDispatcherImpl: before retrying dispatchRemoteHelper, if the query has already timed out, fail fast with a QUERY_TIMEOUT status wrapped in FragmentInstanceDispatchException instead of re-dispatching.
  • ErrorHandlingUtils: map QueryTimeoutRuntimeException to QUERY_TIMEOUT.

Test

  • New RegionReadExecutorTest#testRepeatedRpcCall covers both the consensus-read and VirtualDataRegion paths, asserting the response carries REPEATED_RPC_CALL and readNeedRetry == false.
  • mvn test -pl iotdb-core/datanode -Dtest=RegionReadExecutorTest → 6 passed.
  • mvn compile -pl iotdb-core/datanode (incl. spotless:check) → BUILD SUCCESS.

🤖 Generated with Claude Code

…(NPE)

dispatchRemote retries the same FragmentInstance once after a TException. If the
first delivery already executed and released its context (dataRegion == null) but
the context is still cached in FragmentInstanceManager, the retry reused it and ran
a fresh ALIVE driver on the released context, causing an NPE during init().

- Add REPEATED_RPC_CALL(723) status code (intentionally not retryable).
- FragmentInstanceManager (data + schema paths): when instanceContext.computeIfAbsent
  would reuse an already-cached context for the same instanceId, reject the
  duplicated dispatch with REPEATED_RPC_CALL before the planning try block, so the
  first execution's cached resources are left untouched.
- RegionReadExecutor: carry an IoTDBRuntimeException's status code back to the
  dispatcher so REPEATED_RPC_CALL is not downgraded to EXECUTE_STATEMENT_ERROR.
- FragmentInstanceDispatcherImpl: skip the retry when the query has already timed
  out, failing fast with QUERY_TIMEOUT instead of re-dispatching.
- ErrorHandlingUtils: map QueryTimeoutRuntimeException to QUERY_TIMEOUT.
- Add RegionReadExecutorTest coverage for the status-code propagation.
@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 32.00000% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.82%. Comparing base (a2368b2) to head (33c9436).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...ne/execution/fragment/FragmentInstanceManager.java 0.00% 25 Missing ⚠️
...plan/scheduler/FragmentInstanceDispatcherImpl.java 0.00% 8 Missing ⚠️
.../org/apache/iotdb/db/utils/ErrorHandlingUtils.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #17794      +/-   ##
============================================
- Coverage     40.82%   40.82%   -0.01%     
- Complexity     2611     2612       +1     
============================================
  Files          5184     5184              
  Lines        350965   351000      +35     
  Branches      44895    44898       +3     
============================================
+ Hits         143297   143301       +4     
- Misses       207668   207699      +31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

sonarqubecloud Bot commented Jun 1, 2026

Copy link
Copy Markdown

@JackieTien97
JackieTien97 merged commit 958ce45 into master Jun 1, 2026
42 of 43 checks passed
@JackieTien97
JackieTien97 deleted the ty/fixOpt branch June 1, 2026 02:39
MileaRobertStefan pushed a commit to MileaRobertStefan/iotdb that referenced this pull request Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant