Repository navigation
Conversation
Instance locks exist only inside one process, so a second API process started against the same data directory could save over the first one's metadata and run its startup reconcilers against guests the first one owns. The binary has no flags, so running it to look for a version was enough to start one. The API now takes an exclusive flock on the data directory before it reads or writes anything in it, and exits if another process holds the lock. The configuration is loaded once, so the directory that is locked is the one the rest of startup uses. Older binaries do not take the lock, so the old process has to be stopped before this one starts.
Keep the lock on one persistent inode without requiring private read access to the whole data directory. Check its type, owner and permissions before flock, and verify that exec releases the descriptor. Document storage cutovers as offline operations: guest metadata and socket paths retain the configured directory name.
This branch has not been deployed
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
The API takes an exclusive, nonblocking
flockon<data_dir>/.hypeman.lockbefore loading guest state. It exits if another API process already holds the lock. The lock file is created with mode0600and kept across restarts, so a user with only read access to the directory cannot take the lock.Instance locks exist only inside one process. A second API process started against the same data directory runs the whole of startup against guests the first one owns before it fails to bind the port. The binary has no flags, so running it to look for a version is enough to start one.
The configuration is loaded once.
data_diris cleaned the same way guest storage paths are before the API takes the lock. The lock stays held until process exit, even if startup returns an error or background jobs are still writing during shutdown. Executed child programs do not inherit it.Split out of #555. It stands alone, and #555's fork recovery relies on it: with one writer guaranteed, a fork still marked at startup has no live owner.
Upgrade note
Stop the old API before upgrading or downgrading; older binaries do not take this lock. Moving storage, changing its mount, or repointing a
data_dirsymlink requires stopping the guests and the API first. Existing guest metadata and sockets retain the configured path (DEVELOPMENT.md).Testing
TestServerRefusesSecondWriterBeforeStartupstarts the server in a subprocess against a locked data directory, reached through a symlink, and checks it exits at the lock without creating any guest or system state.TestServerKeepsStorageDirectoryLockedUntilExitchecks the storage directory reached through a path containing a symlink and... A failed startup still holds that lock afterrun()returns; the next owner can acquire it after the process exits.go vetpassed.mainmainbind: address already in use(74 log lines)mainNot covered
.hypeman.lockwhile the API is running; file existence does not indicate whether the lock is held.