Skip to content

Commit fc72c6f

Browse files
committed
feat: Add connection-level timeout for improved stability
- Add 5-minute connection timeout to prevent hanging connections - Implement proper timeout handling with tokio::time::timeout - Add comprehensive error logging for connection timeouts - Prevents resource leaks and improves server stability under load Connection-level timeouts are essential for production deployments to prevent resource exhaustion when clients disconnect unexpectedly or network issues cause connections to hang indefinitely.
1 parent cf69c7e commit fc72c6f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

datafusion-postgres/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,17 @@ pub async fn serve_with_handlers(
133133
let tls_acceptor_ref = tls_acceptor.clone();
134134

135135
tokio::spawn(async move {
136-
if let Err(e) = process_socket(socket, tls_acceptor_ref, factory_ref).await {
137-
warn!("Error processing socket: {e}");
136+
// Add connection timeout to prevent hanging connections
137+
let timeout_duration = std::time::Duration::from_secs(300); // 5 minutes
138+
match tokio::time::timeout(timeout_duration, process_socket(socket, tls_acceptor_ref, factory_ref)).await {
139+
Ok(result) => {
140+
if let Err(e) = result {
141+
warn!("Error processing socket: {e}");
142+
}
143+
}
144+
Err(_) => {
145+
warn!("Connection timed out after {} seconds", timeout_duration.as_secs());
146+
}
138147
}
139148
});
140149
}

0 commit comments

Comments
 (0)