[KYUUBI #7035] Close the operation by operation manager to prevent operation leak

### Why are the changes needed?

To fix the operation leak if the session init timeout.

1. the operationHandle has not been added into session `opHandleSet` (super.runOperation).
2. The `operation.close()` only close the operation, but it does not remove it from `handleToOperation` map.
3. the session close would not remove the opHandle from `handleToOperation` as it has not been added into session `opHandleSet`

So here we can resolve the operation leak by invoking `operationManager.closeOperation` to remove the operation handle and close session.
cc68cb4c85/kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiSessionImpl.scala (L235-L246)

cc68cb4c85/kyuubi-common/src/main/scala/org/apache/kyuubi/session/AbstractSession.scala (L100-L103)

cc68cb4c85/kyuubi-common/src/main/scala/org/apache/kyuubi/operation/OperationManager.scala (L127-L130)

cc68cb4c85/kyuubi-common/src/main/scala/org/apache/kyuubi/session/AbstractSession.scala (L89-L92)

FYI: the operation was added into `handleToOperation` during new operation.
cc68cb4c85/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/KyuubiOperationManager.scala (L56-L64)

### How was this patch tested?

Minor change.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes #7035 from turboFei/remove_op.

Closes #7035

3c376833a [Wang, Fei] close by op mgr

Authored-by: Wang, Fei <fwang12@ebay.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
Wang, Fei 2025-04-24 14:14:07 +08:00 committed by Cheng Pan
parent 9e8bdf51a2
commit ba854d3c99
No known key found for this signature in database
GPG Key ID: 8001952629BCC75D

View File

@ -238,7 +238,7 @@ class KyuubiSessionImpl(
waitForEngineLaunched()
} catch {
case t: Throwable =>
operation.close()
sessionManager.operationManager.closeOperation(operation.getHandle)
throw t
}
sessionEvent.totalOperations += 1