Skip to content

Commit

Permalink
Merge pull request #8944 from yufan022/main
Browse files Browse the repository at this point in the history
fix(mysql): fix mysql conns leak
  • Loading branch information
BohuTANG authored Nov 24, 2022
2 parents bb2c9a9 + 265f21e commit 5f78113
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/query/service/src/sessions/session_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl SessionManager {
let config = self.get_conf();
{
let sessions = self.active_sessions.read();
if sessions.len() == self.max_sessions {
if sessions.len() >= self.max_sessions {
return Err(ErrorCode::TooManyUserConnections(
"The current accept connection has exceeded max_active_sessions config",
));
Expand All @@ -106,11 +106,9 @@ impl SessionManager {
let mut mysql_conn_id = None;
match session_typ {
SessionType::MySQL => {
let mut conn_id_session_id = self.mysql_conn_map.write();
let conn_id_session_id = self.mysql_conn_map.read();
mysql_conn_id = Some(self.mysql_basic_conn_id.fetch_add(1, Ordering::Relaxed));
if conn_id_session_id.len() < self.max_sessions {
conn_id_session_id.insert(mysql_conn_id, id.clone());
} else {
if conn_id_session_id.len() >= self.max_sessions {
return Err(ErrorCode::TooManyUserConnections(
"The current accept connection has exceeded max_active_sessions config",
));
Expand All @@ -128,7 +126,7 @@ impl SessionManager {
let user_api = UserApiProvider::instance();
let session_settings = Settings::try_create(&config, user_api, tenant).await?;
let session_ctx = SessionContext::try_create(config.clone(), session_settings)?;
let session = Session::try_create(id, typ.clone(), session_ctx, mysql_conn_id)?;
let session = Session::try_create(id.clone(), typ.clone(), session_ctx, mysql_conn_id)?;

let mut sessions = self.active_sessions.write();
if sessions.len() < self.max_sessions {
Expand All @@ -142,6 +140,17 @@ impl SessionManager {
sessions.insert(session.get_id(), Arc::downgrade(&session));
}

if let SessionType::MySQL = session_typ {
let mut conn_id_session_id = self.mysql_conn_map.write();
if conn_id_session_id.len() < self.max_sessions {
conn_id_session_id.insert(mysql_conn_id, id);
} else {
return Err(ErrorCode::TooManyUserConnections(
"The current accept connection has exceeded max_active_sessions config",
));
}
}

Ok(session)
} else {
Err(ErrorCode::TooManyUserConnections(
Expand Down

1 comment on commit 5f78113

@vercel
Copy link

@vercel vercel bot commented on 5f78113 Nov 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

databend – ./

databend-databend.vercel.app
databend.vercel.app
databend.rs
databend-git-main-databend.vercel.app

Please sign in to comment.