Wei-hao-Li opened a new pull request, #19033: URL: https://github.com/apache/iotdb/pull/19033
**Problem** After KILL QUERY is issued against a table-model query whose device-schema fetch is spilling to disk, the original query returns 305 INTERNAL_SERVER_ERROR together with an internal java.nio.file.NoSuchFileException: .../device-entry/<queryId>/.../raw/segment-00XXXX.tmp, instead of 715 QUERY_WAS_KILLED. **Root cause** When a query is killed, the two sides race: 1. KILL QUERY calls QueryExecution.cancel(), which synchronously moves the state machine to CANCELED and records the QUERY_WAS_KILLED (715) status. The state-change listener then asynchronously releases resources, including DeviceEntrySpillManager.deregisterQuery(), which deletes the whole device-entry/<queryId>/ directory. 2. At the same time, the planning thread is still inside startInternal() — the coordinator-side "fetch device for query ..." subquery is writing device entries to that same spill directory (TableDeviceSchemaFetcher.appendToMaterializer → DeviceEntryDiskSpiller). Once the directory has been deleted, the next segment write fails with NoSuchFileException, wrapped as UncheckedIOException. That RuntimeException escapes QueryExecution.start() and travels up through Coordinator.execution() to ClientRPCServiceImpl.executeStatementInternal. ErrorHandlingUtils.onQueryException does not recognize it, so it falls back to INTERNAL_SERVER_ERROR (305) and appends the raw exception message, overriding the already-recorded 715 status. **Fix** In QueryExecution.start(), when a RuntimeException is caught and the state machine has already reached a terminal state (e.g. CANCELED), the exception is logged as a warning and swallowed, because it is caused by resources being released concurrently and the terminal status recorded by the state machine is authoritative. Unfinished queries still propagate the exception as before, and Errors are always rethrown. With this change, getStatus() reports the recorded 715 Query was killed by others to the client. -- 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]
