You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "PDGGK (via GitHub)" <gi...@apache.org> on 2026/08/10 17:41:18 UTC
[PR] Throw instead of returning partial results when ExecutorEngine is interrupted [shardingsphere]
PDGGK opened a new pull request, #39400:
URL: https://github.com/apache/shardingsphere/pull/39400
## Changes
`ExecutorEngine.getGroupResults` restored the interrupt flag and then **fell through**, so the loop kept going, every remaining `Future.get()` threw immediately, and the method returned a result list silently missing one entry per interrupted group — reported to the caller as success.
The two handlers sitting next to each other were asymmetric:
```java
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt(); // restores the flag, falls through
} catch (final ExecutionException ex) {
return throwException(ex); // terminates
}
```
This adds the missing `return throwException(ex)` to the interrupt branch. One line.
## Why this is a regression, not a design choice
Before 551478707 (#25627) the handler was combined and rethrew for both:
```diff
- } catch (final InterruptedException | ExecutionException ex) {
+ } catch (final InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ } catch (final ExecutionException ex) {
return throwException(ex);
}
```
That was an 18-file sweep for the Sonar rule *"Either re-interrupt this method or rethrow the InterruptedException that can be caught here"*. Splitting the catch added the re-interrupt and, as a side effect, dropped the rethrow from that branch.
The rule is satisfied by re-interrupting **or** rethrowing, so doing both — which is what this PR restores — still satisfies it. Nothing about the original sweep's intent is undone.
## Why the short list matters downstream
`BatchPreparedStatementExecutor.accumulate` (`:163-173`) walks every execution unit and indexes the result list positionally:
```java
for (JDBCExecutionUnit eachUnit : each.getInputs()) {
accumulate(executeResults.get(count), result, eachUnit);
count++;
}
```
A missing entry surfaces as an `IndexOutOfBoundsException` a long way from the cause. Silently succeeding with fewer results than execution units is the worse of the two outcomes.
## Testing
`ExecutorEngineTest.assertParallelExecuteThrowsWhenInterrupted`: a first callback that interrupts the trunk thread before returning, and an async callback that blocks so the pending `Future.get()` actually observes the interrupt. On `master`:
```
ExecutorEngineTest.assertParallelExecuteThrowsWhenInterrupted:119
Expected org.apache.shardingsphere.infra.exception.generic.UnknownSQLException
to be thrown, but nothing was thrown.
```
The blocking async side is required, not incidental: a `FutureTask` that has already completed returns its value even with the interrupt flag set, so a non-blocking fixture would pass for the wrong reason.
- `ExecutorEngineTest` — fails before, 3/3 after
- `infra/executor` with `-am` — 2984 tests, 0 failures, 0 errors
- `checkstyle:check -Pcheck` and `spotless:check -Pcheck` — both clean
## One thing I left alone
`MetaDataLoader` has the same swallow from the same sweep and returns a partial metadata map. It looked like a separate fix, and open PR #39157 already touches that file, so I did not bundle it. Happy to follow up once that lands.
Fixes #39399
## Type
- [x] Bugfix
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Throw instead of returning partial results when ExecutorEngine is interrupted [shardingsphere]
Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu merged PR #39400:
URL: https://github.com/apache/shardingsphere/pull/39400
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org