Skip to content

fix(daemon): make idle disconnect updates atomic - #98

Open
NianJiuZst wants to merge 1 commit into
Tencent:mainfrom
NianJiuZst:codex/fix-daemon-idle-close-race
Open

fix(daemon): make idle disconnect updates atomic#98
NianJiuZst wants to merge 1 commit into
Tencent:mainfrom
NianJiuZst:codex/fix-daemon-idle-close-race

Conversation

@NianJiuZst

Copy link
Copy Markdown
Contributor

Summary

  • keep the last IPC activity timestamp and active connection count in one mutex-protected state
  • update connection close count and close timestamp atomically
  • recover poisoned activity-state locks consistently and avoid connection-count underflow
  • add deterministic boundary tests for close/activity idle windows

Why

The close callback previously decremented the atomic connection count before updating the separately locked activity timestamp. The idle task could observe the old expired timestamp between those operations, then see zero connections and shut the daemon down immediately after the last client disconnected instead of starting a fresh idle interval.

An idle check now observes a coherent snapshot: it sees either the still-open connection or the new close timestamp.

Tests

  • cargo test -p bsk --locked
  • cargo clippy -p bsk --all-targets --locked -- -D warnings
  • cargo test -p bsk --test idle_exit --locked -- --test-threads=1
  • repeated the last-connection disconnect regression 3 additional times

@NianJiuZst
NianJiuZst marked this pull request as ready for review August 17, 2026 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant