ruanwenjun opened a new issue, #7828:
URL: https://github.com/apache/kyuubi/issues/7828
### Code of Conduct
- [x] I agree to follow this project's Code of Conduct.
### Search before asking
- [x] I searched existing issues and compared the related timeout-checker
reports.
### Describe the bug
An engine that accepts a cleanup RPC but never returns a response can leave
Kyuubi Server waiting indefinitely. The wait occurs while holding locks needed
by other requests and by the server's single session timeout-checker.
In `KyuubiSyncThriftClient`:
- The main engine transport is created with a socket read timeout of `0`.
- `withLockAcquiredAsyncRequest` holds the client lock while calling
`Future.get()` without a timeout.
In `KyuubiOperation.cancel()`, the server first sets its local state to
CANCELED and then calls the engine while holding the operation lock. If the
engine does not return:
1. The RPC executor remains in `recv_CancelOperation -> socketRead0`.
2. The frontend cancellation handler remains in `Future.get()`, holding both
the operation lock and the client lock.
3. Other requests using the same client, including operation-log fetching,
wait for the client lock.
4. When the canceled operation becomes eligible for idle cleanup, the
session timeout-checker calls `operation.close()` and waits for the operation
lock.
5. Because the timeout-checker is a single scheduled thread, timeout
checking and automatic expired-operation/session cleanup for the entire server
instance stop making progress.
The server's local CANCELED state therefore does not establish that
cancellation completed on the engine. An engine session and its application
resources can remain alive after the client has already failed or disconnected.
### Affects Version(s)
Observed on a downstream Kyuubi 1.9.1-based build (1.9.1.2), with a JDK
8u322 server and Spark 3.3.2 engine.
The unbounded wait and locking pattern are also present in upstream master
at `0fd62e5b0cdb7689f8e458f26c3d229418e64ba3`. The production observation and
thread dumps are from the downstream build; a synthetic regression against
master has not yet been run.
### Kyuubi Server Log Output
Production identifiers have been removed. The server thread dump shows:
```text
engine RPC executor:
SocketInputStream.socketRead0
TCLIService$Client.recv_CancelOperation
KyuubiSyncThriftClient.cancelOperation
frontend cancellation handler:
FutureTask.get
KyuubiSyncThriftClient.withLockAcquiredAsyncRequest
KyuubiSyncThriftClient.cancelOperation
KyuubiOperation.cancel
TFrontendService.CancelOperation
owns: operation lock A and client lock B
operation execution thread:
ReentrantLock.lock
KyuubiSyncThriftClient.withLockAcquired
KyuubiSyncThriftClient.fetchResults
ExecuteStatement.fetchQueryLog
waits for: client lock B
session timeout-checker:
ReentrantLock.lock
KyuubiOperation.close
AbstractSession.closeExpiredOperations
SessionManager...run
waits for: operation lock A
```
The logs and later thread dump establish this sequence:
- The server marked the operation CANCELED, but its cancellation RPC did not
return.
- About three hours later, the timeout-checker logged that the operation had
timed out and would be closed.
- No further periodic session timeout-check messages appeared in the
remainder of that day's server log.
- A subsequent server thread dump, more than 40 hours after cancellation
began, still showed the same cancellation handler holding both locks and the
timeout-checker waiting for lock A.
- Engine logs continued to report one open session.
The operation cleanup log is emitted before `operation.close()` completes;
it is not evidence that remote cleanup succeeded.
### Reproduction and expected behavior
A proposed regression scenario, independent of the engine's original failure:
1. Use a test engine that opens a session and returns an operation handle.
2. Let it accept CancelOperation but keep its response pending while the
connection remains open.
3. Send cancellation through Kyuubi Server.
4. Allow the server operation's idle timeout to expire.
5. Verify that cancellation has a bounded failure path and that the
timeout-checker can continue checking other sessions.
An optional variant can keep a separate engine-aliveness probe responsive.
The probe uses another connection/session, so a successful probe does not
guarantee that the original cleanup RPC can complete.
Expected behavior:
- Cleanup RPCs and any client-lock waits on their path must have a bounded
failure path.
- A timed-out call must not leave the transport, executor task, or lock
ownership indefinitely blocking subsequent cleanup.
- A transport with an unresolved in-flight response must not be reused as
though the RPC had completed.
- One unresponsive engine operation must not indefinitely disable timeout
checking for the whole server instance.
- Failure reporting should distinguish the server's local state from an
unconfirmed engine-side cancellation.
### Additional context
Related timeout-checker discussion: #5499. Here the checker is parked on a
lock held across an unresponsive engine RPC; exception handling around the
scheduled task alone cannot release that lock.
This is separate from the appender deadlock reported in #7826 and fixed by
#7827. That incident exposed the server's unbounded wait, but an engine can
fail to respond for other reasons as well. Fixing the appender alone does not
provide a general server-side failure boundary.
Relevant source at the inspected master revision:
- [RPC client locking and unbounded
Future.get](https://github.com/apache/kyuubi/blob/0fd62e5b0cdb7689f8e458f26c3d229418e64ba3/kyuubi-server/src/main/scala/org/apache/kyuubi/client/KyuubiSyncThriftClient.scala#L165-L192)
- [Engine transport creation with socket read timeout
0](https://github.com/apache/kyuubi/blob/0fd62e5b0cdb7689f8e458f26c3d229418e64ba3/kyuubi-server/src/main/scala/org/apache/kyuubi/client/KyuubiSyncThriftClient.scala#L495-L510)
- [Cancellation and close under the operation
lock](https://github.com/apache/kyuubi/blob/0fd62e5b0cdb7689f8e458f26c3d229418e64ba3/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/KyuubiOperation.scala#L137-L168)
- [Single session
timeout-checker](https://github.com/apache/kyuubi/blob/0fd62e5b0cdb7689f8e458f26c3d229418e64ba3/kyuubi-common/src/main/scala/org/apache/kyuubi/session/SessionManager.scala#L332)
No raw production logs, credentials, host addresses, session IDs, or
application IDs are attached.
### Are you willing to submit PR?
- [x] Yes. I would be willing to submit a PR with guidance from the Kyuubi
community to fix.
--
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]