{"record":{"id":"867df1f3bf323a34","repo":"risingwavelabs/risingwave","slug":"terminating-connection-due-to-idle-in-transaction","errorCode":null,"errorMessage":"terminating connection due to idle-in-transaction timeout","messagePattern":"terminating connection due to idle-in-transaction timeout","errorType":"error_code","errorClass":"PsqlError","httpStatus":null,"severity":"error","filePath":"src/utils/pgwire/src/error.rs","lineNumber":84,"sourceCode":"    IoError(#[from] IoError),\n\n    /// Uncategorized error for describe, bind.\n    #[error(transparent)]\n    Uncategorized(\n        #[from]\n        #[backtrace]\n        BoxedError,\n    ),\n\n    #[error(\"Panicked when handling the request: {0}\nThis is a bug. We would appreciate a bug report at:\n  https://github.com/risingwavelabs/risingwave/issues/new?labels=type%2Fbug&template=bug_report.yml\")]\n    Panic(String),\n\n    #[error(\"Unable to setup an SSL connection\")]\n    SslError(#[from] openssl::ssl::Error),\n\n    #[error(\"terminating connection due to idle-in-transaction timeout\")]\n    IdleInTxnTimeout,\n\n    #[error(\"Server throttled: {0}\")]\n    ServerThrottle(String),\n}\n\n#[derive(Debug)]\npub struct ProtocolViolationError(String);\n\nimpl fmt::Display for ProtocolViolationError {\n    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n        self.0.fmt(f)\n    }\n}\n\nimpl std::error::Error for ProtocolViolationError {\n    fn provide<'a>(&'a self, request: &mut std::error::Request<'a>) {\n        request.provide_value(PostgresErrorCode::ProtocolViolation);","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/utils/pgwire/src/error.rs#L66-L102","documentation":"The server terminates the connection because the session stayed inside a transaction (idle-in-transaction) longer than the configured timeout. This mirrors Postgres's `idle_in_transaction_session_timeout` behavior.","triggerScenarios":"A client opens a transaction (BEGIN) and then remains idle — issuing no further statements — past the idle-in-transaction timeout configured on the server.","commonSituations":"Applications that BEGIN a transaction and forget to COMMIT/ROLLBACK; connection poolers holding open transactions; hung application logic mid-transaction; long pauses in interactive psql sessions inside a transaction.","solutions":["Ensure transactions are committed or rolled back promptly; don't hold them while idle.","Increase the idle-in-transaction timeout setting if the current limit is too aggressive.","Fix application code that leaks open transactions (check for missing COMMIT/ROLLBACK on error paths).","Reconnect after termination; the connection cannot be reused once this error is raised."],"exampleFix":"// before: BEGIN then long idle, no commit\nconn.begin(); awaitUserInput();\n// after: only open the txn when ready\nawaitUserInput(); conn.begin(); doWork(); conn.commit();","handlingStrategy":"validation","validationCode":"-- before running long work, check the setting\nSHOW idle_in_transaction_session_timeout;\n-- ensure no txn left open:\nSELECT state FROM pg_stat_activity WHERE state = 'idle in transaction';","typeGuard":null,"tryCatchPattern":"match err {\n    PsqlError::IdleInTxnTimeout => reconnect_and_replay(),\n    other => return Err(other),\n}","preventionTips":["Always pair BEGIN with COMMIT/ROLLBACK, including on error paths.","Use connection-pool health checks that reject idle-in-transaction connections.","Set application-level statement/transaction timeouts below the server timeout.","Monitor pg_stat_activity for sessions idle in transaction."],"tags":["transaction","timeout","connection-terminated"],"backgroundTag":"request-timeout","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}