zhaorongsheng opened a new pull request, #65895:
URL: https://github.com/apache/doris/pull/65895

   ## Problem
   
   In a multi-FE + load-balancer setup, `KILL QUERY <connectionId>` silently 
fails when the kill request reaches a different FE than the one that owns the 
connection.
   
   **Root cause:** `killByConnectionId()` only searched the local 
`ConnectScheduler` and returned `ERR_NO_SUCH_THREAD` immediately—without trying 
other FEs.  By contrast, `killQueryByQueryId()` (kill by string query ID) 
already had complete cross-FE forwarding via `FEOpExecutor`.
   
   This inconsistency also affects **MySQL JDBC `setQueryTimeout()`**: when 
`queryTimeoutKillsConnection=false`, the driver opens a new TCP connection and 
sends `KILL QUERY <origConnId>`.  That new connection can land on a different 
FE, causing the kill to fail silently.
   
   ## Fix
   
   Align `killByConnectionId` with `killQueryByQueryId`:
   
   1. **`KillUtils.killByConnectionId`** — add `OriginStatement stmt` 
parameter; when the connection is not found locally and `ctx.isProxy()==false`, 
iterate alive non-self FEs and forward the statement via `FEOpExecutor`; return 
on the first `OK` response.  `ctx.isProxy()` guard prevents infinite forwarding 
loops (same pattern as `killQueryByQueryId`).
   
   2. **`KillConnectionCommand.doRun`** — pass `executor.getOriginStmt()` 
instead of `null`, so the statement is available for cross-FE forwarding.
   
   ## Tests
   
   - Updated `KillCommandTest` and `KillUtilsTest` to the new 4-arg 
`killByConnectionId` signature.
   - **New unit test** `testKillByConnectionIdForwardToOtherFE`: connection not 
found locally, not proxy, stmt non-null → forwards to remote FE and succeeds.
   - **New unit test** `testKillByConnectionIdProxyNoForward`: `isProxy=true` → 
throws `ERR_NO_SUCH_THREAD` without calling `getFrontends()`.
   - **New regression test** `test_kill_query_by_connection_id` (p0): starts a 
long `SELECT sleep(60)` in a background thread, kills it with `KILL QUERY 
<connectionId>`, and asserts the query disappears from `SHOW PROCESSLIST`.
   
   ## Checklist
   
   - [ ] I have added test cases for my fix.
   - [ ] This PR covers the fix described above.


-- 
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]

Reply via email to