[Bug][Arrow Flight SQL] DDL statements via Flight SQL crash with getMysqlChannel RuntimeException after 4.0.5 CLIENT_DEPRECATE_EOF fix
- Dominant language
- Java
- Stars
- 15.9k
- Forks
- 3.9k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 520
Description
### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/doris/issues) and found no similar issues.
### Version
4.0.5
### What happened
DDL statements (CREATE DATABASE, CREATE TABLE, etc.) executed via Arrow Flight SQL protocol crash with:
```
java.lang.RuntimeException: getMysqlChannel not in mysql connection
```
This is a regression introduced in **4.0.5** (works in 4.0.3). The root cause is commit `1a8590e0b22` ("[fix](protocol) Support CLIENT_DEPRECATE_EOF to fix empty result with MySQL driver 9.5.0 #61050 (#61062)").
### Root Cause Analysis
The CLIENT_DEPRECATE_EOF fix added `context.getMysqlChannel().clientDeprecatedEOF()` calls in `StmtExecutor.java` at two locations (lines ~1537 and ~1587):
```java
if (!context.getMysqlChannel().clientDeprecatedEOF()) {
// send EOF packet
}
```
These code paths are also traversed during **Flight SQL DDL execution**. However, `FlightSqlConnectContext.getMysqlChannel()` throws `RuntimeException("getMysqlChannel not in mysql connection")` (see `FlightSqlConnectContext.java:54-56`), because Flight SQL does not use MySQL channels.
The fix should add a `connectType` check before calling `getMysqlChannel()`:
```java
if (context.getConnectType() == ConnectType.MYSQL
&& !context.getMysqlChannel().clientDeprecatedEOF()) {
// send EOF packet
}
```
Similar guards already exist in other parts of the codebase, e.g., `InsertIntoTableCommand.java:383`:
```java
if (ctx.getConnectType() == ConnectType.MYSQL && ctx.getMysqlChannel() != null) {
ctx.getMysqlChannel().reset();
}
```
### Full Stack Trace
```
INTERNAL: [FlightSQL] get flight info statement failed, after executeQueryStatement handleQuery,
java.lang.RuntimeException: after executeQueryStatement handleQuery, error code: ERR_UNKNOWN_ERROR,
error msg: RuntimeException, msg: getMysqlChannel not in mysql connection (Internal; ExecuteQuery)
at org.apache.doris.service.arrowflight.sessions.FlightSqlConnectContext.getMysqlChannel(FlightSqlConnectContext.java:55)
at org.apache.doris.qe.StmtExecutor.sendFields(StmtExecutor.java:1537)
```
### What you expected to happen
DDL statements should execute successfully via Arrow Flight SQL, as they did in 4.0.3.
### How to reproduce
1. Connect to Doris 4.0.5 using ADBC Flight SQL client (e.g., `adbc_driver_flightsql`)
2. Execute any DDL statement:
```python
import adbc_driver_flightsql.dbapi as flight_sql
conn = flight_sql.connect(uri="grpc://fe-host:8070", db_kwargs={"username": "root", "password": "pass"})
cursor = conn.cursor()
cursor.execute("CREATE DATABASE IF NOT EXISTS test_db") # CRASHES
```
3. Error: `RuntimeException: getMysqlChannel not in mysql connection`
### Anything else
- **Workaround**: Execute DDL statements via the HTTP SQL API (`POST /api/query/{catalog}/{db}`) instead of Flight SQL.
- **Affected versions**: 4.0.5, 4.0.5-rc01
- **Working versions**: 4.0.3-rc03 and earlier
- **Regression commit**: 1a8590e0b22 (cherry-pick of #61050 as #61062)
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
Contributor guide
Assessment
This issue has not been assessed yet.