Repository navigation
fix: signal handling - remove in-flight temporary containers when ddev is interrupted, fixes #8951 - #8954
Conversation
|
Download this PR's build for your OS and architecture with: ddev utility download-ddev --pr 8954Or download the artifact for your OS and architecture directly:
See Testing a PR. |
0ca63ef to
530024c
Compare
|
I ran When
Everything else looks right to me. |
|
It failed in automated tests on macOS Docker Desktop also, thanks for report, https://buildkite.com/ddev/ddev-macos-arm64-mutagen/builds/14766#01a14054-e758-4575-959c-62674b9e2242 It will be interesting to see what happens on other macOS tests. Edit: Amazing, Colima, Lima, Orbstack succeeded. And DD failed. Basically the only failure. (WSL is Github runner failure) |
530024c to
3546080
Compare
stasadev
left a comment
There was a problem hiding this comment.
Looks good to me with a suggestion:
WaitIfExiting() covers util.Failed() and Execute(), but pkg/dockerutil/networks.go:54 calls output.UserErr.Fatalf() directly and can run mid-start. If it fires while the handler is removing a container, the process exits, the ContainerRemove is cancelled, and we're back to the race. Switching it to util.Failed() closes that. The other direct Fatalf calls are in globalconfig startup, before any temp container exists.
Claude Code also ran TestInterruptRemovesTemporaryContainers on Linux/Docker: it passes on this branch and fails on main with a leftover GetExistingDBType-* container.
🤖 Developed with assistance from Claude Code
3546080 to
d5807ac
Compare
|
Thanks, rebased and done |
|
Added an additional cleanup with cleanup of export-db partials and |
| // The snapshot is copied out to a temp dir and renamed into db_snapshots, | ||
| // so an interrupted copy never leaves a partial snapshot there. | ||
| hostTmpDir, err := os.MkdirTemp(app.GetConfigPath(""), ".snapshot") |
There was a problem hiding this comment.
Snapshot() stages the dump in .ddev/.snapshotNNN, which is in neither the Mutagen ignore list (mutagen_config_assets/mutagen.yml has only db_snapshots and .importdb*) nor the .ddev/.gitignore list in config.go. With Mutagen, a multi-GB snapshot starts syncing into the web container until it is renamed away, and a dir left behind by SIGKILL shows up in git status. Either add .snapshot* to both lists, or create the temp dir inside db_snapshots/, which both already ignore and which keeps the rename on one filesystem (ListSnapshotNames() would then need to skip dot entries).
🤖 Developed with assistance from Claude Code
|
Found another issue: Lines 1188 to 1205 in 81594f2 🤖 Generated with Claude Code |
81594f2 to
a543d3d
Compare
…ixes ddev#8951 ## Short Summary (TL;DR) Ctrl-C, SIGTERM, or a closed terminal no longer leaves utility containers such as `start-chown-*` and `GetExistingDBType-*` behind holding project volumes, because ddev now removes them before it exits. ## The Issue - Fixes ddev#8951 ddev had no signal handler, so Go exited at once on SIGINT or SIGTERM and the deferred `RemoveContainer()` in `RunSimpleContainerExtended()` never ran. ## How This PR Solves The Issue A new `pkg/interrupt` package installs one handler from `main()`. Code registers cleanup with `OnInterrupt()`, and on a signal the handler runs it in parallel with a short timeout, then exits. A second signal during cleanup exits immediately. - `pkg/dockerutil` tracks each container `RunSimpleContainerExtended()` creates until it is removed, plus a terminal in raw mode, and restores the terminal before force-removing the containers. - `ImportDB()` also registers removal of its `.ddev/.importdbNNN` directory, which holds the extracted dump inside the project and was left behind the same way. - `ddev share`, `ddev mutagen logs`, `ddev tui`, and `exec.RunInteractiveCommandWithOutput()` handle Ctrl-C and SIGTERM themselves, so they call `Delegate()` for those signals and the handler runs the cleanup without exiting. The forwarder in `pkg/exec` also stops its notification and no longer panics when forwarding fails. - On Unix ddev re-raises the signal after cleanup instead of exiting with 130 or 143, because bash only stops a loop on Ctrl-C when its child died from the signal. - Signals the parent already ignores stay ignored, so `nohup` and background jobs in scripts keep working. ## Manual Testing Instructions ```bash ddev utility download-ddev --pr 8954 export PATH="$HOME/tmp/ddev-download-ddev/pr-8954:$PATH" mkdir ~/tmp/intr && cd ~/tmp/intr && ddev config --project-type=php ddev start -y & p=$!; sleep 2; kill -TERM $p; wait $p docker ps -a --filter label=com.ddev.platform=ddev --format '{{.Names}}' | grep -v '^ddev-' # Expect no output; before this PR a start-chown-* container was left ``` On Windows, press Ctrl-C during `ddev start` in PowerShell and in Git Bash, then run the same `docker ps` check. ## Automated Testing Overview `TestInterruptRemovesTemporaryContainers` sends SIGTERM to `ddev start` once a temporary container exists, then checks that ddev died from SIGTERM and that no temporary containers remain. It is skipped on Windows. `pkg/interrupt` has unit tests for the timeout, delegation, and exit codes. 🤖 Developed with assistance from [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 5.5 <[email protected]>
The interrupt handler's listener and os/signal's loop run for the whole process, which put TestCmdStart at 11 goroutines against a limit of 10. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ks in-flight work Removing an in-flight temporary container makes RunSimpleContainerExtended() fail, and the main goroutine then reached util.Failed() and exited with status 1 before the handler re-raised the signal. Docker Desktop on macOS hit this every time, because its forced remove stops the container well before the API call returns, so TestInterruptRemovesTemporaryContainers failed there. Once the handler is going to exit, util.Failed() and Execute() now block in interrupt.WaitIfExiting() and leave the exit to the handler, which also drops the misleading error message. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lure EnsureDdevNetwork() exited through output.UserErr.Fatalf(), which skips WaitIfExiting(), so a failure there during an interrupt could exit before the handler finished removing temporary containers. It now uses util.Failed(), which waits. The interrupt handler also logs the error from ContainerWait instead of discarding it, which errcheck requires. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rtial dumps or snapshots A Docker exec keeps running in the container after ddev exits, so an interrupted import-db, export-db, or snapshot kept loading or dumping the database. Exec now takes an InterruptID that runs the command under a wrapper shell carrying a marker in its cmdline, and an interrupt kills that shell's process group. The marker is in cmdline rather than environ because rootless podman refuses reads of another process's environ. export-db -f wrote the dump in place, so an interrupt left a truncated file under the requested name and destroyed any earlier one. It now writes a temp file beside the target and renames it on success. A snapshot was copied straight into db_snapshots, so an interrupt during the copy left a partial snapshot that looked restorable. It is now copied to a temp dir in .ddev and renamed in, and an interrupt also removes the in-container copy. WaitIfExiting now runs as a cobra finalizer, because cobra printed the failing command's error and usage before Execute() could wait for the handler. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rrupt kills a db command The snapshot temp dir was created 0700, which a db container user mapped to another uid cannot write into on rootless Docker, so every snapshot failed there. It now gets 0777 like db_snapshots. When the interrupt cleanup killed an InterruptID command, the caller still printed its failure before the handler exited, as ddev snapshot did with its warning. Exec now waits for the handler in that case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…f Mutagen and git `ddev export-db -f /dev/stdout >> backup.sql` replaced backup.sql on Linux, and on macOS `> out.sql` failed, because /dev/stdout resolved to a regular file and went through the temp-file-and-rename path. A dump path under /dev is now opened for append, so the shell's redirect decides whether to truncate. The .ddev/.snapshotNNN staging dir is now ignored by Mutagen and by .ddev/.gitignore, like .importdb*, so a large snapshot doesn't start syncing and a dir left by SIGKILL doesn't show in git status. Co-Authored-By: Claude Opus 5.5 <[email protected]>
a543d3d to
c5dbded
Compare
## Short Summary (TL;DR) Adds the DDEV v1.25.5 release post, with before/after recordings of the rebuilt `ddev tui`, and records how to make such recordings in the `blog-images` skill. The post explains that the PHP fixes for CVE-2026-109618 and CVE-2026-109619 matter locally only with `ddev share` or casual hosting, and that production servers need the PHP update. ## How This PR Solves The Issue The post follows the v1.25.4 one and the release notes in ddev/ddev#8926. The three `ddev tui` WebPs stack v1.25.4 above v1.25.5 and were recorded with VHS against demo projects in an isolated global config; their tapes and ffmpeg filter graphs are in `public/img/blog/2026/10/vhs/` so they can be re-recorded. The `blog-images` skill gets a new `gif-comparison.md` with what took several attempts to get right for these recordings: demo projects in an isolated `DDEV_XDG_CONFIG_HOME` instead of real ones, a font size that stays readable after the blog scales the image, short clips per feature with captions shown before each key, and timing captions from ffmpeg scene detection, because VHS sleeps do not match video time. ## Manual Testing Instructions Open `https://pr-759.ddev-com-fork-previews.pages.dev/blog/release-v1-25-5/` and compare it with the v1.25.4 post at https://ddev.com/blog/release-v1-25-4/. Check that the three `ddev tui` recordings play and are readable at the column width, and that the `ddev launch --qr` screenshot shows the whole QR code. ## Release/Deployment Notes Before publishing, replace the `8.5.XX`-style PHP versions and the PHP announcement link, check the PR count, and drop the Ctrl-C and symlinked agent socket sentences if ddev/ddev#8954 or ddev/ddev#8963 don't make the release. 🤖 Developed with assistance from [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 5.5 <[email protected]>
stasadev
left a comment
There was a problem hiding this comment.
Snapshot staging dir and >> backup.sql are fixed now, thanks. One problem left with the new /dev/ check, see the inline comment.
| // redirected to, which it has already truncated or opened for append, so it | ||
| // is appended to rather than replaced. | ||
| func createDumpFile(dumpFile string) (f *os.File, finish func(ok bool) error, err error) { | ||
| if strings.HasPrefix(dumpFile, "/dev/") { |
There was a problem hiding this comment.
This also catches regular files under /dev. Claude Code ran ddev export-db --gzip=false -f /dev/shm/db.sql on Linux with Docker 29:
| file doesn't exist | file exists | |
|---|---|---|
| main | created | replaced |
| this PR | open /dev/shm/db.sql: no such file or directory |
appended, two dumps in one file |
The second case is bad because the result looks like a valid backup. On Windows /dev/backup.sql is C:\dev\backup.sql and gets the same.
Maybe match only fd paths, and skip it on Windows?
if !nodeps.IsWindows() && (dumpFile == "/dev/stdout" || dumpFile == "/dev/stderr" || strings.HasPrefix(dumpFile, "/dev/fd/")) {Or use os.Stdout directly for /dev/stdout. That would also fix ddev export-db -f /dev/stdout > out.sql 2>&1, where the "Wrote database dump..." message overwrites the start of the dump, because the reopened /proc/self/fd/1 has its own offset. This one already happens on main, so it can be a follow-up.
🤖 Reviewed with assistance from Claude Code
…argets in export-db The previous check matched every path under /dev, so `ddev export-db -f /dev/shm/db.sql` failed when the file didn't exist and appended a second dump when it did, and on Windows `/dev/backup.sql` meant `C:\dev\backup.sql`. Other paths under /dev are created or replaced again, like any dump file. /dev/stdout and /dev/stderr now write through ddev's own stdout and stderr instead of reopening them, so with `> out.sql 2>&1` the closing message comes after the dump instead of overwriting its start. Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Short Summary (TL;DR) Adds the DDEV v1.25.5 release post, with before/after recordings of the rebuilt `ddev tui`, and records how to make such recordings in the `blog-images` skill. The post explains that the PHP fixes for CVE-2026-109618 and CVE-2026-109619 matter locally only with `ddev share` or casual hosting, and that production servers need the PHP update. ## How This PR Solves The Issue The post follows the v1.25.4 one and the release notes in ddev/ddev#8926. The three `ddev tui` WebPs stack v1.25.4 above v1.25.5 and were recorded with VHS against demo projects in an isolated global config; their tapes and ffmpeg filter graphs are in `public/img/blog/2026/10/vhs/` so they can be re-recorded. The `blog-images` skill gets a new `gif-comparison.md` with what took several attempts to get right for these recordings: demo projects in an isolated `DDEV_XDG_CONFIG_HOME` instead of real ones, a font size that stays readable after the blog scales the image, short clips per feature with captions shown before each key, and timing captions from ffmpeg scene detection, because VHS sleeps do not match video time. ## Manual Testing Instructions Open `https://pr-759.ddev-com-fork-previews.pages.dev/blog/release-v1-25-5/` and compare it with the v1.25.4 post at https://ddev.com/blog/release-v1-25-4/. Check that the three `ddev tui` recordings play and are readable at the column width, and that the `ddev launch --qr` screenshot shows the whole QR code. ## Release/Deployment Notes Before publishing, replace the `8.5.XX`-style PHP versions and the PHP announcement link, check the PR count, and drop the Ctrl-C and symlinked agent socket sentences if ddev/ddev#8954 or ddev/ddev#8963 don't make the release. 🤖 Developed with assistance from [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Short Summary (TL;DR) Adds the DDEV v1.25.5 release post, with before/after recordings of the rebuilt `ddev tui`, and records how to make such recordings in the `blog-images` skill. The post explains that the PHP fixes for CVE-2026-109618 and CVE-2026-109619 matter locally only with `ddev share` or casual hosting, and that production servers need the PHP update. ## How This PR Solves The Issue The post follows the v1.25.4 one and the release notes in ddev/ddev#8926. The three `ddev tui` WebPs stack v1.25.4 above v1.25.5 and were recorded with VHS against demo projects in an isolated global config; their tapes and ffmpeg filter graphs are in `public/img/blog/2026/10/vhs/` so they can be re-recorded. The `blog-images` skill gets a new `gif-comparison.md` with what took several attempts to get right for these recordings: demo projects in an isolated `DDEV_XDG_CONFIG_HOME` instead of real ones, a font size that stays readable after the blog scales the image, short clips per feature with captions shown before each key, and timing captions from ffmpeg scene detection, because VHS sleeps do not match video time. ## Manual Testing Instructions Open `https://pr-759.ddev-com-fork-previews.pages.dev/blog/release-v1-25-5/` and compare it with the v1.25.4 post at https://ddev.com/blog/release-v1-25-4/. Check that the three `ddev tui` recordings play and are readable at the column width, and that the `ddev launch --qr` screenshot shows the whole QR code. ## Release/Deployment Notes Before publishing, replace the `8.5.XX`-style PHP versions and the PHP announcement link, check the PR count, and drop the Ctrl-C and symlinked agent socket sentences if ddev/ddev#8954 or ddev/ddev#8963 don't make the release. 🤖 Developed with assistance from [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Short Summary (TL;DR) Adds the DDEV v1.25.5 release post, with before/after recordings of the rebuilt `ddev tui`, and records how to make such recordings in the `blog-images` skill. The post explains that the PHP fixes for CVE-2026-109618 and CVE-2026-109619 matter locally only with `ddev share` or casual hosting, and that production servers need the PHP update. ## How This PR Solves The Issue The post follows the v1.25.4 one and the release notes in ddev/ddev#8926. The three `ddev tui` WebPs stack v1.25.4 above v1.25.5 and were recorded with VHS against demo projects in an isolated global config; their tapes and ffmpeg filter graphs are in `public/img/blog/2026/10/vhs/` so they can be re-recorded. The `blog-images` skill gets a new `gif-comparison.md` with what took several attempts to get right for these recordings: demo projects in an isolated `DDEV_XDG_CONFIG_HOME` instead of real ones, a font size that stays readable after the blog scales the image, short clips per feature with captions shown before each key, and timing captions from ffmpeg scene detection, because VHS sleeps do not match video time. ## Manual Testing Instructions Open `https://pr-759.ddev-com-fork-previews.pages.dev/blog/release-v1-25-5/` and compare it with the v1.25.4 post at https://ddev.com/blog/release-v1-25-4/. Check that the three `ddev tui` recordings play and are readable at the column width, and that the `ddev launch --qr` screenshot shows the whole QR code. ## Release/Deployment Notes Before publishing, replace the `8.5.XX`-style PHP versions and the PHP announcement link, check the PR count, and drop the Ctrl-C and symlinked agent socket sentences if ddev/ddev#8954 or ddev/ddev#8963 don't make the release. 🤖 Developed with assistance from [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Short Summary (TL;DR)
Ctrl-C, SIGTERM, or a closed terminal no longer leaves utility containers such as
start-chown-*andGetExistingDBType-*behind holding project volumes, because ddev now removes them before it exits.The Issue
Inspired by @wazum work in #8950 and @stasadev #8777. We've needed this for a long time.
ddev had no signal handler, so Go exited at once on SIGINT or SIGTERM and the deferred
RemoveContainer()inRunSimpleContainerExtended()never ran.How This PR Solves The Issue
A new
pkg/interruptpackage installs one handler frommain(). Code registers cleanup withOnInterrupt(), and on a signal the handler runs it in parallel with a short timeout, then exits. A second signal during cleanup exits immediately. See the appendix for how the pieces fit together.pkg/dockerutiltracks each containerRunSimpleContainerExtended()creates until it is removed, plus a terminal in raw mode, and restores the terminal before force-removing the containers.ImportDB()also registers removal of its.ddev/.importdbNNNdirectory, which holds the extracted dump inside the project and was left behind the same way.ddev import-db,ddev export-db, andddev snapshotrun their in-container command under a wrapper shell whose process group the handler kills, because a Docker exec otherwise keeps running in the container after ddev exits.ddev export-db -fwrites a temp file and renames it on success, and a snapshot is copied to a temp dir in.ddevand renamed intodb_snapshots, so an interrupt never leaves a truncated dump or a partial snapshot that looks valid./dev/stdoutand/dev/stderrare written through ddev's own descriptors and/dev/fd/Nis opened for append instead, so>> backup.sqlkeeps its earlier contents, and the.ddev/.snapshot*temp dir is ignored by Mutagen and.ddev/.gitignore.ddev share,ddev mutagen logs,ddev tui, andexec.RunInteractiveCommandWithOutput()handle Ctrl-C and SIGTERM themselves, so they callDelegate()for those signals and the handler runs the cleanup without exiting. The forwarder inpkg/execalso stops its notification and no longer panics when forwarding fails.nohupand background jobs in scripts keep working.Manual Testing Instructions
The temporary containers live for less than a second, so watch them from a second terminal with
docker events. The filter hides the once-a-second healthcheck execs and the project's ownddev-*containers:Every
createshould get a matchingdestroybefore the prompt returns. In the first terminal:Also check by hand:
ddev startprintsInterrupted, removing N temporary containers...when one was in flight.for i in 1 2 3; do ddev stop; ddev start; donestops at the first Ctrl-C instead of moving on.ddev sharestill prints "Stopping tunnel" on Ctrl-C, andddev mutagen logsstill restarts the daemon.ddev import-db --file=<large dump>interrupted with Ctrl-C leaves no.ddev/.importdb*directory.ddev export-db -f dump.sql.xzandddev snapshoton a large database, interrupted with Ctrl-C, leave no new file in the project or.ddev/db_snapshots, keep an earlierdump.sql.xz, and leave nomariadb-dumpormariabackupinddev exec -s db ps -ef.ddev startin PowerShell and in Git Bash, and closing the console window, leave nothing behind in thedocker pscheck above.Automated Testing Overview
TestInterruptRemovesTemporaryContainerssends SIGTERM toddev startonce a temporary container exists, then checks that ddev died from SIGTERM and that no temporary containers remain. It is skipped on Windows.pkg/interrupthas unit tests for the timeout, delegation, and exit codes.Appendix: how the interrupt handler works
interrupt.Install()runs once inmain()and starts a goroutine that listens for SIGINT, SIGTERM, and SIGHUP on Unix, or Ctrl-C and SIGTERM on Windows, where Go never delivers SIGHUP.OnInterrupt(f) (unregister)fto the cleanup list;fgets a context with a deadlineDelegate(sigs...) (release)On a signal the handler copies the cleanup list and runs every entry in parallel, waiting up to 5 seconds, or 3 for SIGTERM on Windows, where a closed console window is ended about 5 seconds later. If the signal is delegated it returns there and the command's own handling continues. Otherwise it exits as soon as cleanup finishes or a second signal arrives. While it cleans up,
util.Failed()andExecute()wait for it instead of exiting, because removing a container makes the command that was using it fail, and exiting on that failure would report an error instead of dying from the signal. Cleanups stay registered after they run, because a delegated signal does not end the process and the next one needs them again.pkg/dockerutilregisters one at init that works from the IDsRunSimpleContainerExtended()records right afterContainerCreateand drops after its ownRemoveContainer, plus the restore functionsetupRawTerminal()records. It restores the terminal first so its message is readable, then force-removes each container. When ddev's own deferred removal is already under way, it waits for the container to disappear instead, because exiting first would cancel that removal and leave adeadcontainer.ImportDB()registers removal of its temporary directory and unregisters it in the samedeferthat removes it on a normal return, which is the pattern for any new short-lived resource.ExportDB()does the same for its temp file, andSnapshot()for its temp dir and in-container copy.app.Exec()with anInterruptIDprependssh -c '"$@"; exit $?' ddev-interrupt-<id>to the command, and its cleanup finds that marker in/proc/*/cmdlineand kills the wrapper's process group, which a Docker exec makes it lead.The handler leaves alone project containers already started by
docker compose upand Mutagen sessions, as #8951 proposed. SIGKILL and crashes cannot be caught, so the sweeps inddev delete(#8950) andddev poweroffstill cover those.🤖 Developed with assistance from Claude Code
Co-Authored-By: Claude Opus 5.5 [email protected]