Skip to content

Per-plug lock, so two jobs cannot switch a plug at once - #10

Merged
virzak merged 1 commit into
masterfrom
feature/plug-lock
Nov 29, 2026
Merged

virzak merged 1 commit into
masterfrom
feature/plug-lock

Conversation

@virzak

@virzak virzak commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Two jobs sharing a bench plug could switch it at the same time, or cycle it in the middle of the other's test run.

  • on, off and cycle take the plug's lock (an OS file lock per MAC, released when the process ends, even on a crash). When it is held they fail with "plug bench is locked by since ", or wait with --wait-lock 5m. --holder / PLUGCTL_HOLDER names the holder; the default is the pid and host.
  • plugctl lock <plug> -- <command> holds the lock while the command runs and exits with its status. plugctl calls inside it switch as usual (the MAC is passed down in PLUGCTL_HELD_LOCKS).
  • After waiting for a lock, plugctl reconnects and rereads the plug, since the other job may have switched it.
  • state --json gains on_since.
  • The image keeps locks in /config/locks.

Locks cover one machine (or containers sharing /config); they do not coordinate two machines.

Library: Locks, PlugLock, Connected::lock, Controller::with_locks / with_lock_wait, and Error::Locked. A Connected now holds the lock from its first switch until it is dropped.

Tested: unit tests for refusal, waiting and the held-by-parent list, and a controller test that a locked plug is not switched. On a real plug that was already on: on inside lock succeeds, a second job is refused with the holder's name, --wait-lock waits it out, and the exit status passes through.

Two jobs sharing a bench plug could cycle it at once, or cycle it in
the middle of each other's test run.
@virzak
virzak merged commit dc8bc5c into master Nov 29, 2026
12 checks passed
@virzak
virzak deleted the feature/plug-lock branch November 29, 2026 21:28
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