matanper opened a new pull request, #70722:
URL: https://github.com/apache/doris/pull/70722
### What problem does this PR solve?
Issue Number: close #70451
Related PR: None
Problem Summary:
`ConnectProcessor.handleQuery` swallowed every exception from `executeQuery`:
```java
} catch (UserException exception) {
LOG.warn("execute query exception", exception);
} catch (Exception ignored) {
// saved use handleQueryException
}
```
The comment holds only for a failure inside `StmtExecutor.execute()`, whose
own catch calls `handleQueryException`. An exception thrown **before** that
leaves the state OK from `ctx.getState().reset()`: nothing sets an error or
writes an audit record, and a non-`UserException` is not even logged. Code that
can throw there:
- before the statement loop: the cloud request metrics block and
`SqlDialectHelper.convertSqlByDialect`;
- per statement: `beforeStatement`, `resolveWorkloadGroupName()`, `new
StmtExecutor(...)`, and the profile and executor setup up to `ctx.setExecutor`.
As a result:
- MySQL clients get an OK packet for a statement that never ran.
- Over Arrow Flight SQL, `DorisFlightSqlProducer.executeQueryStatement` sees
a non-ERR state, `isReturnResultFromLocal()` still true, and an empty channel.
It then answers a `SELECT` with `addOKResult`, the synthetic one-row
`StatusResult = "0"` table meant for `SET`/`USE`. A client reading rows by
position or name takes that row as the query's answer.
We hit this in production (cloud mode, many Arrow Flight SQL sessions):
occasional `SELECT`s answered with a `StatusResult` row, with no audit entry
and no FE log line.
### What this PR changes
- **A statement whose setup throws is reported where it fails.** The
per-statement setup gets its own catch. It logs at WARN and calls
`handleQueryException` with the statement's own text and parsed statement,
after clearing the query id that still names the previous statement. It then
rethrows, so the rest of the request is skipped, as for an execution failure.
- **A failure before the statement loop is reported by `handleQuery`.** It
is logged at WARN and goes through `handleQueryException(exception, originStmt,
null, null)`. The Flight producer's existing ERR check then fails
`GetFlightInfo` instead of publishing a `StatusResult` ticket.
- **A statement is never reported twice.** Once the loop is reached, every
statement is reported inside it. So `handleQuery` only reports exceptions from
before the loop; it does not use "state is not ERR" for this. This covers the
edge case raised in the issue triage. `StatementContext.close()` in the
per-statement `finally` can rethrow a planner-resource close failure after a
statement ran and was audited with an OK state. That statement keeps its
outcome and is not audited again. The exception, which used to be dropped
silently, is now logged at WARN.
- Unchanged: a failure during execution keeps its own error and its single
audit record. `ConnectionException` still propagates. A `UserException` from
execution still logs `execute query exception`.
This fixes the reporting. Whatever exception is behind a given production
occurrence will now show up as a WARN (`statement failed before execution` /
`request failed before its statements executed`) with its stack trace.
### Release note
Report and audit a statement that fails before it starts executing, instead
of answering it as successful. Over Arrow Flight SQL such a `SELECT` used to
return a single `StatusResult` row.
### Check List (For Author)
- Test: Unit Test — new `ConnectProcessorPreExecutionFailureTest` (10 cases):
- setup failure (`RuntimeException` and `UserException`) inside the loop
→ ERR, one audit record as that statement, with no stale query id;
- failure before the loop → ERR and one audit record;
- multi-statement request: the 2nd statement's setup fails → 1st audited
as OK, 2nd audited as ERR with its own text, 3rd does not run;
- execution failure keeps its own error and one audit record;
- `StatementContext.close()` failure after a successful, audited
statement → not turned into ERR and not audited again;
- `ConnectionException` still propagates;
- through the real `DorisFlightSqlProducer` (failure while building the
executor, and a failure in the dialect conversion before the loop) →
`GetFlightInfo` fails, no `StatusResult` result is published, one audit record;
a `SET` over Flight still answers OK.
Ran with `./run-fe-ut.sh --run`:
- With the fix: `ConnectProcessorPreExecutionFailureTest` 10/10, plus
`ConnectProcessorRetryTest`, `ConnectProcessorForwardProtocolTest`,
`AuditLogWorkloadGroupTest`, `DorisFlightSqlProducerTest` and
`FlightSqlExecutionSchemaTest` all pass (58/58).
- Without the fix (only `ConnectProcessor.java` reverted): 6 of the 10
new tests fail (`expected: <ERR> but was: <OK>`; the Flight cases get a
`FlightInfo` instead of an error). The other 4 cover behaviour that must not
change and pass either way.
- Behavior changed: Yes. A statement that fails before it executes now
returns an error and is audited, instead of reporting success.
- Does this need documentation: No
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]