Fix: Ensure tempfile::TempDir lives long enough for OctopiiNode initialization#8
Open
miky-rola wants to merge 1 commit intonubskr:masterfrom
Open
Fix: Ensure tempfile::TempDir lives long enough for OctopiiNode initialization#8miky-rola wants to merge 1 commit intonubskr:masterfrom
miky-rola wants to merge 1 commit intonubskr:masterfrom
Conversation
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
This PR addresses a bug in the client example code where the temporary directory intended for the Write-Ahead Log (WAL) was being deleted immediately upon creation due to improper scope management of the
tempfile::TempDirguardThe Problem
The original code used
tempfile::tempdir()?.path().to_path_buf()inline:// Original code
let oct_cfg = OctopiiConfig {
// ...
wal_dir: tempfile::tempdir()?.path().to_path_buf(),
// ...
};
Reason for my change
In rust, the tempfile::TempDir struct manages the directory's lifecycle through RAII; When the temporary TempDir object created by tempfile::tempdir() was not bound to a variable, it was dropped immediately after the oct_cfg initialization line completed
The fix is to bind the result of tempfile::tempdir() to a local variable (temp_dir) that lives for the duration of the main function's scope
My added code
let temp_dir = tempfile::tempdir()?; // temp_dir now keeps the directory alive
let wal_dir_path = temp_dir.path().to_path_buf();
let oct_cfg = OctopiiConfig {
// ...
wal_dir: wal_dir_path,
// ...
};