fix: track created disks in the state file so an interrupt cannot orphan them - #160
Merged
Conversation
tas50
force-pushed
the
fix/track-created-disks-in-state
branch
2 times, most recently
from
August 23, 2026 18:51
c72bc4b to
de43dfa
Compare
…han them
Standalone disks were recorded in an instance variable, and the cleanup
that deletes them hangs off `rescue => e`, which catches StandardError.
Interrupt is not a StandardError, so Ctrl-C during a create -- the most
common way a create ends early -- skipped cleanup entirely and left a
billable disk behind with no record of it anywhere:
disks: tk-datadisk-...-extra-disk 20GB (no users)
state: --- {}
kitchen destroy -> Finished destroying (0m0.00s)
Record the disks in the Test Kitchen state file instead, which is written
whatever happens, and have `destroy` delete anything still recorded once
the instance is gone. This mirrors what the instance itself already does.
Two supporting changes are needed to make that reachable:
- Pin the zone before any billable resource exists. In region mode it is
chosen at random, so cleanup would not otherwise know where to look.
- Record the server name before the insert request is issued rather than
after it returns. Live testing turned up a case where GCE created the
instance but the interrupted request never returned, so the state file
had the disk but not the instance holding it, and cleanup failed with
resourceInUseByAnotherResource.
Confirmed against a real project: an interrupted create is now fully
reclaimed by `kitchen destroy`, leaving no instances and no disks.
tas50
force-pushed
the
fix/track-created-disks-in-state
branch
from
August 23, 2026 19:44
de43dfa to
4d37187
Compare
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.
The bug
Pressing Ctrl-C during a
kitchen createthat uses extra disks orphans a billable disk with no record of it anywhere:Why
created_disk_nameswas@created_disk_names ||= []— in memory only. The cleanup that consumes it hangs offcreate'srescue => e, which catchesStandardError.Interruptis not aStandardError, so Ctrl-C skips the rescue, and the process exits with the only record of the disk in a variable that just died with it.Standalone disks are created before
insert_instanceand bill from creation, so this window is wide open — it is the whole "Creating a N GB disk / Waiting for disk to be ready" phase.The fix
Record the disks in the state file, which Test Kitchen writes whatever happens (
ensure state_file.write(state)), and havedestroydelete anything still recorded once the instance is gone. This is the treatment the instance itself already gets.Two supporting changes make that reachable:
resourceInUseByAnotherResource. Recording the name first closes that window, and fix: clear the state file when the instance is already gone #159 makesdestroytolerate a name that never became an instance.Verification
bundle exec rspec— 331 examples, 0 failures. Five new specs; three of them failwhen only
lib/kitchen/driver/gce.rbis reverted tomain.bundle exec rubocopreports 5Lint/DuplicateMethodsoffenses, all of themalready on
main— fix: leave room for the disk name when generating an instance name #162 and fix: downcase instance names instead of mangling them #163 each added the same five private helpers togce.rband neither merge removed the duplicate. Not introduced here, and fixedseparately.
Final state: 0 instances, 0 disks.