[KYUUBI #2422] Wrap close session with try-finally

### _Why are the changes needed?_

close #2422

### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #2423 from wForget/KYUUBI-2422.

Closes #2422

94ac9ed1 [wforget] [KYUUBI-2422] Wrap close session with try-finally

Authored-by: wforget <643348094@qq.com>
Signed-off-by: ulysses-you <ulyssesyou@apache.org>
This commit is contained in:
wforget 2022-04-20 09:36:16 +08:00 committed by ulysses-you
parent 6017917100
commit 70a3005ea7
No known key found for this signature in database
GPG Key ID: 4C500BC62D576766
2 changed files with 10 additions and 4 deletions

View File

@ -118,8 +118,11 @@ abstract class SessionManager(name: String) extends CompositeService(name) {
throw KyuubiSQLException(s"Invalid $sessionHandle")
}
info(s"$sessionHandle is closed, current opening sessions $getOpenSessionCount")
session.close()
deleteOperationLogSessionDir(sessionHandle)
try {
session.close()
} finally {
deleteOperationLogSessionDir(sessionHandle)
}
}
private def deleteOperationLogSessionDir(sessionHandle: SessionHandle): Unit = {

View File

@ -95,8 +95,11 @@ class KyuubiSessionManager private (name: String) extends SessionManager(name) {
override def closeSession(sessionHandle: SessionHandle): Unit = {
val session = getSession(sessionHandle)
super.closeSession(sessionHandle)
limiter.foreach(_.decrement(UserIpAddress(session.user, session.ipAddress)))
try {
super.closeSession(sessionHandle)
} finally {
limiter.foreach(_.decrement(UserIpAddress(session.user, session.ipAddress)))
}
}
def openBatchSession(