Skip to content

Commit

Permalink
fix when idle_in_transaction_session_timeout = 0
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzl25 committed Jan 17, 2024
1 parent 4f75d1c commit dcacd31
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/frontend/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl FrontendEnv {
// Idle transaction background monitor
let join_handle = tokio::spawn(async move {
let mut check_idle_txn_interval =
tokio::time::interval(core::time::Duration::from_secs(5));
tokio::time::interval(core::time::Duration::from_secs(10));
check_idle_txn_interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
check_idle_txn_interval.reset();
loop {
Expand Down Expand Up @@ -1173,18 +1173,22 @@ impl Session for SessionImpl {
fn check_idle_in_transaction_timeout(&self) -> PsqlResult<()> {
// In transaction.
if matches!(self.transaction_status(), TransactionStatus::InTransaction) {
// Hold the `exec_context` lock to ensure no new sql coming when unpin_snapshot.
let guard = self.exec_context.lock();
// No running sql i.e. idle
if guard.as_ref().and_then(|weak| weak.upgrade()).is_none() {
// Idle timeout.
if let Some(elapse_since_last_idle_instant) = self.elapse_since_last_idle_instant()
{
if elapse_since_last_idle_instant
> self.config().idle_in_transaction_session_timeout() as u128
let idle_in_transaction_session_timeout =
self.config().idle_in_transaction_session_timeout() as u128;
// Idle transaction timeout has been enabled.
if idle_in_transaction_session_timeout != 0 {
// Hold the `exec_context` lock to ensure no new sql coming when unpin_snapshot.
let guard = self.exec_context.lock();
// No running sql i.e. idle
if guard.as_ref().and_then(|weak| weak.upgrade()).is_none() {
// Idle timeout.
if let Some(elapse_since_last_idle_instant) =
self.elapse_since_last_idle_instant()
{
self.unpin_snapshot();
return Err(PsqlError::IdleInTxnTimeout);
if elapse_since_last_idle_instant > idle_in_transaction_session_timeout {
self.unpin_snapshot();
return Err(PsqlError::IdleInTxnTimeout);
}
}
}
}
Expand Down

0 comments on commit dcacd31

Please sign in to comment.