Repository navigation
Fix connection limiter lock file handling - #1107
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| struct ConnectionLimiter { | ||
| path: PathBuf, | ||
| } | ||
|
|
||
| impl ConnectionLimiter { | ||
| fn open(path: PathBuf) -> Result<Self, DaemonError> { | ||
| if let Some(parent) = path.parent() { | ||
| if !parent.as_os_str().is_empty() { | ||
| fs::create_dir_all(parent).map_err(|error| lock_file_error(&path, error))?; | ||
| } | ||
| } | ||
|
|
||
| let file = OpenOptions::new() | ||
| .create(true) | ||
| .read(true) | ||
| .write(true) | ||
| .open(&path) | ||
| .map_err(|error| lock_file_error(&path, error))?; | ||
|
|
||
| drop(file); | ||
|
|
||
| Ok(Self { path }) | ||
| } | ||
|
|
||
| fn acquire( | ||
| self: &Arc<Self>, | ||
| module: &str, | ||
| limit: NonZeroU32, | ||
| ) -> Result<ConnectionLockGuard, ModuleConnectionError> { | ||
| let mut file = self.open_file().map_err(ModuleConnectionError::io)?; | ||
| file.lock_exclusive().map_err(ModuleConnectionError::io)?; | ||
|
|
||
| let result = self.increment_count(&mut file, module, limit); | ||
| let unlock_result = file.unlock().map_err(ModuleConnectionError::io); | ||
|
|
||
| drop(file); | ||
|
|
||
| match (result, unlock_result) { | ||
| (Ok(_), Ok(_)) => Ok(ConnectionLockGuard { | ||
| limiter: Arc::clone(self), | ||
| module: module.to_string(), | ||
| }), | ||
| (Err(error), Ok(_)) => Err(error), | ||
| (Ok(_), Err(error)) => Err(error), | ||
| (Err(primary), Err(_)) => Err(primary), | ||
| } |
There was a problem hiding this comment.
Clean lock-file counts when daemon restarts
The new ConnectionLimiter persists connection counts directly in the lock file (read_counts/write_counts on every acquire) but open() simply creates the file if missing and never clears or reconciles existing counts. If the daemon is terminated abruptly while a connection is active (e.g. kill ‑9, crash, power loss), the count written by increment_count remains on disk and no guard drop runs to call decrement. On the next daemon start, increment_count reads that stale value and immediately rejects all new connections with @ERROR: max connections ... even though no sessions are running. Upstream rsync tolerates crashes by using per-connection lock files so stale entries vanish when processes exit. Consider either truncating the lock file on startup or storing per‑PID entries so stale counts are ignored.
Useful? React with 👍 / 👎.
Restores `.github/workflows/coverage.yml` to run on push to master and on pull requests, replacing the workflow_dispatch-only gate applied in #3460 to work around the nightly llvm-cov 22.1 SIGSEGV. Pins the toolchain to nightly-2026-04-20, the last nightly known to work before the LLVM coverage mapping regression. The job remains informational (continue-on-error) so it cannot block master while coverage climbs from the current ~84% baseline toward the CLAUDE.md target of >= 95% line coverage. Step summary now records target vs gate, line and branch percentages, the gate outcome, and per-crate breakdowns. LCOV (line + branch) and HTML reports are uploaded as artifacts with 30-day retention.
Restores `.github/workflows/coverage.yml` to run on push to master and on pull requests, replacing the workflow_dispatch-only gate applied in #3460 to work around the nightly llvm-cov 22.1 SIGSEGV. Pins the toolchain to nightly-2026-04-20, the last nightly known to work before the LLVM coverage mapping regression. The job remains informational (continue-on-error) so it cannot block master while coverage climbs from the current ~84% baseline toward the <internal-tool-doc> target of >= 95% line coverage. Step summary now records target vs gate, line and branch percentages, the gate outcome, and per-crate breakdowns. LCOV (line + branch) and HTML reports are uploaded as artifacts with 30-day retention.
Summary
Testing
cargo test