Skip to content

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

Open
JackieTien97 wants to merge 1 commit into
masterfrom
ty/fixOpt
Open

Fix repeated RPC dispatch reusing a released FragmentInstanceContext (NPE)#17794
JackieTien97 wants to merge 1 commit 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.
@sonarqubecloud
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

❌ Patch coverage is 33.33333% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.82%. Comparing base (2ba2914) to head (c2193aa).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
...ne/execution/fragment/FragmentInstanceManager.java 0.00% 23 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.78%   40.82%   +0.04%     
  Complexity     2610     2610              
============================================
  Files          5184     5184              
  Lines        350861   351001     +140     
  Branches      44888    44900      +12     
============================================
+ Hits         143082   143302     +220     
+ Misses       207779   207699      -80     

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

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