Fix: Add Electrum timeout to connections#147
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a configurable idle timeout for Electrum client connections, aiming to automatically close connections that have been inactive for a specified period (defaulting to 600 seconds) to reduce resource usage from lingering clients.
Changes:
- Added a new CLI/config option
--electrum-idle-timeoutand correspondingConfig::electrum_idle_timeoutfield. - Tracked per-connection last request time and added a periodic idle check loop.
- Closed Electrum connections that exceed the configured idle timeout since the last client request.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/electrum/server.rs |
Tracks last client request time per connection and closes connections that exceed the configured idle timeout. |
src/config.rs |
Adds electrum_idle_timeout to configuration, CLI arg parsing, and default value (600s). |
Comments suppressed due to low confidence (1)
src/electrum/server.rs:589
- Idle timeout is measured only from the last client request (
last_request_atis updated only forMessage::Request). For clients that rely on long-lived subscriptions (server sends periodic notifications but the client may not send further requests), this will disconnect an otherwise active connection after the timeout. If the goal is to close truly idle sockets, consider tracking last activity (read or write) and updating the timestamp onPeriodicUpdate/send_values, or clarify via config/flag semantics that subscriptions require explicit client keepalives (e.g.,server.ping).
Message::Request(line) => {
self.last_request_at = Instant::now();
let result = self.handle_line(&line);
self.send_values(&[result])?
}
Message::PeriodicUpdate => {
let values = self
.update_subscriptions()
.chain_err(|| "failed to update subscriptions")?;
self.send_values(&values)?
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mononaut
approved these changes
May 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For now I think the default of 600 seconds sounds fine.