fix(cclip): improve error handling for stale lock file cleanup#21
Merged
fix(cclip): improve error handling for stale lock file cleanup#21
Conversation
Greptile SummaryFixed stale lock file detection by verifying process existence before blocking cclip mode startup. Previously, lock files left after crashes would permanently block startup until manually removed. Key improvements:
Minor considerations:
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| src/process.rs | Added process_exists() function using kill(pid, 0) pattern - straightforward and correct implementation |
| src/main.rs | Improved lock file handling with stale detection and cleanup, handles corrupted PIDs gracefully, minor PID reuse edge case |
Sequence Diagram
sequenceDiagram
participant User
participant Main as main.rs
participant Process as process.rs
participant FS as File System
participant OS as Operating System
User->>Main: fsel --cclip -d
Main->>FS: read_to_string(lock_path)
alt Lock file exists
FS-->>Main: PID contents
Main->>Main: parse PID from contents
alt Valid PID
Main->>Process: process_exists(pid)
Process->>OS: kill(pid, 0)
OS-->>Process: return code
Process-->>Main: bool (exists/not)
alt Process doesn't exist (stale lock)
Main->>FS: remove_file(lock_path)
Note over Main,FS: Stale lock removed, continue startup
else Process exists & --replace flag
Main->>Process: kill_process_sigterm_result(pid)
Process->>OS: kill(pid, SIGTERM)
OS-->>Process: Result
Main->>FS: remove_file(lock_path)
Main->>Main: sleep(200ms)
else Process exists & no --replace
Main-->>User: Error: already running
end
else Invalid PID (corrupted)
Main->>FS: remove_file(lock_path)
Note over Main,FS: Corrupted lock removed
end
else Lock file doesn't exist
FS-->>Main: NotFound
end
Main->>FS: create(lock_path)
Main->>Process: get_current_pid()
Main->>FS: write PID to lock file
Main->>Main: Create CclipLockGuard (RAII cleanup)
Note over Main: Continue with cclip mode
Greptile found no issues!From now on, if a review finishes and we haven't found any issues, we will not post anything, but you can confirm that we reviewed your changes in the status check section. This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR". |
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.
Summary
Fixes stale lock file detection in cclip mode. The lock file check now verifies if the process actually exists before reporting duhh. "already running", and automatically removes stale lock files left behind after crashes or system restarts.
app doesn't just pray its unlocked anymore
Changes
process_exists()function inprocess.rsto check if a PID is actually runningTesting
cargo build --releasefsel --cclip -d(should work normally)echo "99999" > ~/.cache/fsel/fsel-cclip.lockfsel --cclip -d- should automatically clean up and start--replaceflag: Verify existing process is killed and lock is removedBreaking Changes
None
Related Issues
Fixes #20