-
Notifications
You must be signed in to change notification settings - Fork 39
Description
Problem
Twoliter leaks temporary directories containing the krane binary that is shipped with the tool
Cause
We use lazy_static! to construct a temporary directory where we write the krane binary.
lazy_static::lazy_static! {
pub static ref KRANE: Krane = Krane::seal().unwrap();
}
#[derive(Debug)]
pub struct Krane {
// Hold the file in memory to keep the fd open
_tmp_dir: TempDir,
path: PathBuf,
}This static reference has little guarantee that the inner Drop implementation will be called on process exit, meaning that it's very easy for the tempfile to linger indefinitely.
Proposed Solution
We could refrain from putting krane in a tempfile, and always write it to a defined location (like ./tools). We could alternatively force the caller to tell us where to put it.
Complications
Overwriting a binary that another process is running is problematic (see this article about ETXTBSY.) This makes consistently writing to a known location problematic for concurrent twoliter invocations.
Resolution
We can avoid concurrent run/modify issues of the binary by:
- Only writing
kraneunder./toolsif there is a checksum mismatch - Writing
kraneto a tempfile under./toolsand thenmv-ing it into place so that we get a new inode rather than replacing an existing inode. This means that running processes with a reference to the old inode will continue to work.