Skip to content

fix(ddevapp): read db version from a running container via exec, not a second volume mount (#8658) [skip ci] - #8658

Merged
rfay merged 1 commit into
ddev:mainfrom
rfay:20260802_rfay_existing_db_type_no_volume_conflict
Aug 12, 2026
Merged

rfay merged 1 commit into
ddev:mainfrom
rfay:20260802_rfay_existing_db_type_no_volume_conflict

Conversation

@rfay

@rfay rfay commented Aug 3, 2026

Copy link
Copy Markdown
Member

The Issue

GetExistingDBType() determines the running project's db type/version by
mounting the db volume into a throwaway utility container and reading a
version file from it. If the real db container is already running, that
volume is already attached read-write, and Apple Container's volume
semantics only allow one read-write attacher (or many read-only) at a
time — so the utility-container mount fails and the command errors out.

This is a genuine DDEV bug: any provider that enforces stricter (and
more standard) volume-exclusivity semantics than a permissive Docker
Engine will hit it, so it isn't Apple-Container-specific in principle,
just newly exposed by it.

How This PR Solves The Issue

When the db container is already running, getDBVersionFromVolume() now
execs directly into it to read the version file instead of mounting the
volume into a separate utility container. The version-detection script is
shared (parameterized by explicit file/glob paths) between this fast path
and the original utility-container fallback used when db isn't running,
so MariaDB and both pre-18 and 18+ PostgreSQL data layouts are handled the
same way in either case.

Manual Testing Instructions

  • go test -v ./pkg/ddevapp -run TestGetDBVersionFromVolumeScript
  • Start a project (ddev start), then run a command that calls
    GetExistingDBType() (e.g. ddev config again, or ddev describe)
    while the db container is already running — should succeed instead of
    erroring on the volume mount.

Automated Testing Overview

Added TestGetDBVersionFromVolumeScript in
pkg/ddevapp/db_internal_test.go (whitebox, package ddevapp), covering
MariaDB, pre-18 Postgres, 18+/nested Postgres, precedence between them,
and the not-found case, by running the generated script locally via bash
against a temp directory (no Docker required). The existing
Docker-integration test of the same name in pkg/ddevapp/db_test.go is
unchanged and still passes.

Release/Deployment Notes

None. Pure pkg/ddevapp change, no image dependency.

@github-actions github-actions Bot added the bugfix label Aug 3, 2026
@github-actions

github-actions Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

…a second volume mount

GetExistingDBType() always spun up a utility container mounting the db
volume, even when the real db container was already running and holding
that same volume. On providers where a volume can only be attached
read-write by one container at a time (Apple Container/socktainer,
investigated for ddev#7372), that second mount fails outright with a VZ
storage-attachment error - so `ddev ssh`, `ddev start` and anything else
that calls Start() on an already-running project can never succeed there.
It is also needlessly expensive everywhere else: the function's own
comment already conceded "this has to make a Docker container run so is
fairly costly."

When the db container is already running, read its version file directly
with an exec instead: cheaper on every provider, and the only way this can
succeed at all on providers with exclusive-attach volumes. Falls back to
the original volume-mount approach when the container isn't running
(nonexistent, exited, etc.), where the volume is idle and mounting it
elsewhere is safe - unchanged from today.

Extracted the shared shell script (which locations to check for a MySQL/
MariaDB or PostgreSQL version file, in what order) into
getDBVersionFromVolumeScript(), parameterized by the three file paths to
check, so both the exec-into-the-running-container call and the
utility-container call use the same logic. The live paths
(/var/lib/mysql, /var/lib/postgresql) come from the same layout documented
by GetPostgresDataDir()/GetPostgresDataPath() (see the docker-library/
postgres#1259 comment there for why PostgreSQL 18+ differs from earlier
versions).

Verified against a real project on OrbStack: the exec path returns the
correct type/version in ~650ms while the db container is running, and
stopping the container falls back to the (unchanged) volume-mount path
with the same result.

Added TestGetDBVersionFromVolumeScript as a whitebox test exercising the
shared script directly (no Docker needed) for both the MariaDB and
PostgreSQL pre-18/18+/future-version cases, plus the precedence and
not-found cases. The existing Docker-based integration test of the same
name in db_test.go, which duplicates the utility-container script inline
against a real container, is unchanged and continues to pass.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@rfay
rfay force-pushed the 20260802_rfay_existing_db_type_no_volume_conflict branch from c2403ca to 0ce5dd2 Compare August 8, 2026 15:13
@rfay
rfay marked this pull request as ready for review August 11, 2026 01:19
@rfay
rfay requested a review from a team as a code owner August 11, 2026 01:19

@rfay rfay left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this by stepping through ddev ut get-volume-db-version with project stopped or started, and it was fine. I think we have adequate test coverage. I remember a performance issue about this exact idea long ago that I guess didn't end up getting this part completed. I'm not happy to add the extra code, but I am happy with the more appropriate exec path. I think it can go in just fine.

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

I'm not sure why we're mounting to /var/tmp with ddev/ddev-utilities instead of using /var/lib everywhere, but that's fine.

I confirm that the check is much faster with a project running.

@rfay rfay changed the title fix(ddevapp): read db version from a running container via exec, not a second volume mount fix(ddevapp): read db version from a running container via exec, not a second volume mount (#8658) [skip ci] Aug 12, 2026
@rfay
rfay merged commit bde6f82 into ddev:main Aug 12, 2026
50 checks passed
@rfay
rfay deleted the 20260802_rfay_existing_db_type_no_volume_conflict branch August 12, 2026 13:36
rfay added a commit to rfay/ddev that referenced this pull request Oct 11, 2026
…striction, for ddev#7372 [skip ci]

dbVersionFromRunningContainer() never ran: upstream's getDBVersionFromVolume (ddev#8658) already execs into a running db container and returns before reaching it.

The networks: ["ddev_default"] restriction on db and web never took effect, because fixupComposeYaml adds the default network back to every service. Routing to a multi-homed web container works through socktainer's DNS answering with the querying network's address instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Oct 12, 2026
…striction, for ddev#7372 [skip ci]

dbVersionFromRunningContainer() never ran: upstream's getDBVersionFromVolume (ddev#8658) already execs into a running db container and returns before reaching it.

The networks: ["ddev_default"] restriction on db and web never took effect, because fixupComposeYaml adds the default network back to every service. Routing to a multi-homed web container works through socktainer's DNS answering with the querying network's address instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Oct 20, 2026
…striction, for ddev#7372 [skip ci]

dbVersionFromRunningContainer() never ran: upstream's getDBVersionFromVolume (ddev#8658) already execs into a running db container and returns before reaching it.

The networks: ["ddev_default"] restriction on db and web never took effect, because fixupComposeYaml adds the default network back to every service. Routing to a multi-homed web container works through socktainer's DNS answering with the querying network's address instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Oct 21, 2026
…striction, for ddev#7372 [skip ci]

dbVersionFromRunningContainer() never ran: upstream's getDBVersionFromVolume (ddev#8658) already execs into a running db container and returns before reaching it.

The networks: ["ddev_default"] restriction on db and web never took effect, because fixupComposeYaml adds the default network back to every service. Routing to a multi-homed web container works through socktainer's DNS answering with the querying network's address instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Oct 27, 2026
…striction, for ddev#7372 [skip ci]

dbVersionFromRunningContainer() never ran: upstream's getDBVersionFromVolume (ddev#8658) already execs into a running db container and returns before reaching it.

The networks: ["ddev_default"] restriction on db and web never took effect, because fixupComposeYaml adds the default network back to every service. Routing to a multi-homed web container works through socktainer's DNS answering with the querying network's address instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Oct 31, 2026
…striction, for ddev#7372 [skip ci]

dbVersionFromRunningContainer() never ran: upstream's getDBVersionFromVolume (ddev#8658) already execs into a running db container and returns before reaching it.

The networks: ["ddev_default"] restriction on db and web never took effect, because fixupComposeYaml adds the default network back to every service. Routing to a multi-homed web container works through socktainer's DNS answering with the querying network's address instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants