Skip to content

Fix connection limiter lock file handling - #1107

Merged
oferchen merged 1 commit into
masterfrom
implement-missing-components-for-oc-rsync-mhhmb2
Oct 25, 2025
Merged

oferchen merged 1 commit into
masterfrom
implement-missing-components-for-oc-rsync-mhhmb2

Conversation

@oferchen

@oferchen oferchen commented Oct 25, 2025 •

Copy link
Copy Markdown
Owner

Summary

  • reopen the daemon connection lock file for each update so permission changes and replacements surface as I/O errors
  • simplify the cross-process connection limiter by storing the lock-file path and adding a portable I/O error regression test
  • ensure the connection guard drops invoke the updated limiter path logic without leaking file locks

Testing

  • cargo test

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread crates/daemon/src/lib.rs
Comment on lines +463 to +508
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),
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@oferchen
oferchen merged commit 27e5f7c into master Oct 25, 2025
@oferchen
oferchen deleted the implement-missing-components-for-oc-rsync-mhhmb2 branch October 25, 2025 16:21
oferchen added a commit that referenced this pull request May 1, 2026
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.
oferchen added a commit that referenced this pull request May 5, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant