Skip to content

Commit

Permalink
fix reject parallel session create
Browse files Browse the repository at this point in the history
  • Loading branch information
ariesdevil committed Mar 9, 2022
1 parent 20450a9 commit 1723077
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions query/src/sessions/session_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,9 @@ impl SessionManager {
}

pub async fn create_session(self: &Arc<Self>, typ: impl Into<String>) -> Result<SessionRef> {
let total_sessions = {
let sessions = self.active_sessions.read().await;
sessions.len()
};
match total_sessions == self.max_sessions {
let mut sessions = self.active_sessions.write().await;

match sessions.len() == self.max_sessions {
true => Err(ErrorCode::TooManyUserConnections(
"The current accept connection has exceeded mysql_handler_thread_num config",
)),
Expand All @@ -148,10 +146,8 @@ impl SessionManager {
&self.conf.query.cluster_id,
);

{
let mut sessions = self.active_sessions.write().await;
sessions.insert(session.get_id(), session.clone());
}
sessions.insert(session.get_id(), session.clone());

Ok(SessionRef::create(session))
}
}
Expand Down

0 comments on commit 1723077

Please sign in to comment.