Open
Conversation
… deduplicate nicknames
Comment on lines
+86
to
+100
| pub async fn register( | ||
| &self, | ||
| pid: u32, | ||
| command: String, | ||
| cwd: PathBuf, | ||
| log_file: PathBuf, | ||
| log_handle: tempfile::NamedTempFile, | ||
| ) -> Result<BackgroundProcess> { | ||
| let process = BackgroundProcess { pid, command, cwd, log_file, started_at: Utc::now() }; | ||
| self.lock_processes()?.push(process.clone()); | ||
| self.lock_log_handles()? | ||
| .push(OwnedLogFile { _handle: log_handle, pid }); | ||
| self.metadata.save_process(&process).await?; | ||
| Ok(process) | ||
| } |
Contributor
There was a problem hiding this comment.
Race condition: If save_process() fails on line 98, the in-memory state (lines 95-97) is already corrupted with the process added to both vectors. Subsequent operations will see the process in memory but it won't be persisted to disk, causing inconsistency. Fix by saving to disk first:
pub async fn register(...) -> Result<BackgroundProcess> {
let process = BackgroundProcess { pid, command, cwd, log_file, started_at: Utc::now() };
self.metadata.save_process(&process).await?; // Disk first
self.lock_processes()?.push(process.clone());
self.lock_log_handles()?.push(OwnedLogFile { _handle: log_handle, pid });
Ok(process)
}
Suggested change
| pub async fn register( | |
| &self, | |
| pid: u32, | |
| command: String, | |
| cwd: PathBuf, | |
| log_file: PathBuf, | |
| log_handle: tempfile::NamedTempFile, | |
| ) -> Result<BackgroundProcess> { | |
| let process = BackgroundProcess { pid, command, cwd, log_file, started_at: Utc::now() }; | |
| self.lock_processes()?.push(process.clone()); | |
| self.lock_log_handles()? | |
| .push(OwnedLogFile { _handle: log_handle, pid }); | |
| self.metadata.save_process(&process).await?; | |
| Ok(process) | |
| } | |
| pub async fn register( | |
| &self, | |
| pid: u32, | |
| command: String, | |
| cwd: PathBuf, | |
| log_file: PathBuf, | |
| log_handle: tempfile::NamedTempFile, | |
| ) -> Result<BackgroundProcess> { | |
| let process = BackgroundProcess { pid, command, cwd, log_file, started_at: Utc::now() }; | |
| self.metadata.save_process(&process).await?; | |
| self.lock_processes()?.push(process.clone()); | |
| self.lock_log_handles()? | |
| .push(OwnedLogFile { _handle: log_handle, pid }); | |
| Ok(process) | |
| } | |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
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.
Fixes: #2635
Pending:
Session management