Skip to content

Fix: Ensure tempfile::TempDir lives long enough for OctopiiNode initialization#8

Open
miky-rola wants to merge 1 commit intonubskr:masterfrom
miky-rola:fix/tempdir-scope
Open

Fix: Ensure tempfile::TempDir lives long enough for OctopiiNode initialization#8
miky-rola wants to merge 1 commit intonubskr:masterfrom
miky-rola:fix/tempdir-scope

Conversation

@miky-rola
Copy link

@miky-rola miky-rola commented Nov 28, 2025

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::TempDir guard

The 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,
// ...
};

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