Repository navigation
fix: lock and reread project_list.yaml on every change, never register an empty project name, fixes #9004, fixes #9017 - #9020
Conversation
|
Download this PR's build for your OS and architecture with: ddev utility download-ddev --pr 9020Or download the artifact for your OS and architecture directly:
See Testing a PR. |
…r an empty project name, fixes ddev#9004, fixes ddev#9017 ## Short Summary (TL;DR) Each change to `~/.ddev/project_list.yaml` now happens under a file lock, applied to the list as it is on disk. Concurrent commands no longer drop each other's projects. `ddev config` no longer writes an entry with an empty name when `omit_project_name_by_default` is set. ## The Issue - Fixes ddev#9004 - Fixes ddev#9017 - Part of ddev#8344 (phase 1.1b) ddev#9004: each process wrote back the copy of the list it loaded at startup, so a project registered meanwhile was lost. ddev#9017: the interactive `ddev config` cleared `app.Name` to omit it from config.yaml, and `WriteConfig` then registered the approot under `""`. Only the flag path removed that entry. Afterward `ddev start` failed with "already contains a project named ''", and every `ddev config` elsewhere failed. This needs no concurrency. ## How This PR Solves The Issue - `globalconfig.updateProjectList` takes `project_list.yaml.lock` (gofrs/flock), rereads the file, applies one change, and writes. `ReservePorts`, `SetProjectAppRoot` and `RemoveProjectInfo` use it. `ReadProjectList` reads and sets aside an unparseable file under the same lock. - The lock covers file I/O only, so it uses a plain bounded wait. After 30 seconds it warns and continues unlocked. Root skips it so a root-owned lock file never blocks the user. - New `UpdateProject` checks ports and approot and writes them in one locked step. `UpdateGlobalProjectList` uses it, so a ports-only entry is never written on its own. - `UpdateGlobalProjectList` skips an empty name, and `globalconfig` refuses one. Both `ddev config` paths register the real name after `WriteConfig`. - Reading the list drops a `""` entry, and the next write removes it, so existing broken lists repair themselves. - New `UpdateGlobalConfig` rereads `global_config.yaml` before changing one field. The upgrade prompts and `ddev utility xdebug-diagnose` use it, so they don't revert a change made during the prompt. ## Manual Testing Instructions Use a scratch global directory. Neither test needs Docker. ```bash ddev utility download-ddev --pr 9018 export PATH="$HOME/tmp/ddev-download-ddev/pr-9018:$PATH" export DDEV_XDG_CONFIG_HOME=~/tmp/race-xdg mkdir -p ~/tmp/race-xdg ~/tmp/race/a ~/tmp/race/b ~/tmp/race/c ``` ddev#9017, empty-name entry: ```bash ddev config global --omit-project-name-by-default=true cd ~/tmp/race/c && printf '\n\n\n' | ddev config cat ~/tmp/race-xdg/ddev/project_list.yaml # Expect "c:", not '"":' ``` ddev#9004, lost update. A pre-config hook holds the first `ddev config` between loading and saving the list: ```bash cd ~/tmp/race/a && ddev config --project-type=php --project-name=race-a --omit-containers=db printf 'hooks:\n pre-config:\n - exec-host: sleep 10\n' >> .ddev/config.yaml ddev config --php-version=8.3 & cd ~/tmp/race/b && ddev config --project-type=php --project-name=race-b --omit-containers=db wait grep race- ~/tmp/race-xdg/ddev/project_list.yaml # Expect race-a and race-b; v1.25.4 keeps only race-a ``` ## Automated Testing Overview New tests in `pkg/globalconfig`: - `TestUpdateProjectListKeepsOtherProcessChanges`: an add or remove keeps entries that another process wrote after startup. - `TestConcurrentProjectListWriters`: four test-binary processes register 10 projects each, and all 40 remain. With the lock disabled, only 10 remain. - `TestProjectListEmptyName`: an empty name is refused, and an existing `""` entry is dropped. - `TestUpdateGlobalConfigKeepsOtherProcessChanges`: a field change keeps a value another process wrote. 🤖 Developed with assistance from [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_012F698TBu2Z317rDeLDYkWC
659d543 to
fc99a41
Compare
stasadev
left a comment
There was a problem hiding this comment.
Claude Code ran the #9017 and #9004 repros, and 20 parallel ddev config with different names, on this PR and on main. All of them are fixed here (on main only 1 of 20 projects stays in the list). A few comments inline.
🤖 Reviewed with assistance from Claude Code
| require.Error(t, globalconfig.SetProjectAppRoot("", appRoot)) | ||
| require.Error(t, globalconfig.ReservePorts("", []string{})) | ||
|
|
||
| require.NoError(t, os.WriteFile(globalconfig.GetProjectListPath(), []byte(`"":\n approot: `+appRoot+"\n"), 0644)) |
There was a problem hiding this comment.
This test passes for the wrong reason. The fixture uses backticks, so \n is literal and the YAML doesn't parse. The file is moved to .bad, and the list is empty anyway. With -v it prints Unable to parse global projects file, and the test still passes when the "" drop is removed. This fixes it:
| require.NoError(t, os.WriteFile(globalconfig.GetProjectListPath(), []byte(`"":\n approot: `+appRoot+"\n"), 0644)) | |
| require.NoError(t, os.WriteFile(globalconfig.GetProjectListPath(), []byte("\"\":\n approot: "+appRoot+"\n"), 0644)) |
| fl := flock.New(GetProjectListPath() + ".lock") | ||
| ctx, cancel := context.WithTimeout(context.Background(), projectListLockTimeout) | ||
| defer cancel() | ||
| locked, err := fl.TryLockContext(ctx, 20*time.Millisecond) |
There was a problem hiding this comment.
When the lock is stuck, every lock call waits 30 seconds. With flock project_list.yaml.lock sleep 200 running, ddev config took 61s and showed the warning twice. Maybe remember the timeout for the rest of the process, like gaveUpOnPID in globallock.go?
| if err != nil { | ||
| return err | ||
| } | ||
| // Entries without an approot stay, since ReservePorts writes them. |
There was a problem hiding this comment.
Small thing: ReservePorts is only used in tests now. If we remove it, this exception can go too, and the list can be cleaned the same way on read and on write.
| return nil | ||
| } | ||
|
|
||
| // projectListLockTimeout is a var so tests can shorten it. |
There was a problem hiding this comment.
Small thing: this is not true, no test changes projectListLockTimeout.
| } | ||
|
|
||
| // Restore the name and update global project list with correct name | ||
| // WriteConfig doesn't register an empty name, so register the real one. |
There was a problem hiding this comment.
Not for this PR, maybe a follow-up: both ddev config paths clear app.Name, call WriteConfig, and then restore it. If WriteConfig dropped the name only from appcopy, like it already does for project_tld and other defaults, app.Name would stay real and nothing could register "".
- Give up on a stuck project_list.yaml.lock once per process, so one command waits 30 seconds at most instead of once per list access. - Remove ReservePorts, which only tests used. The list is now cleaned the same way on read and on write: entries without a name or an approot are dropped. - Fix the TestProjectListEmptyName fixture, which did not parse as YAML, so the test passed without checking the empty-name drop. Co-Authored-By: Claude Opus 5.5 <[email protected]>
stasadev
left a comment
There was a problem hiding this comment.
Thanks, all fixed. Claude Code reran the repros on 8705b04: #9017, #9004, 20 parallel ddev config, and the existing "" entry are all good. With a stuck lock, ddev config now waits 30s once instead of 61s. TestProjectListEmptyName now fails if the "" drop is removed.
Small thing: with a broken list, the "incomplete configuration" warning is shown twice in one command, from the read at startup and from the write. util.WarningOnce would create an import cycle, but maybe warn only in ReadProjectList?
The appcopy part is in #9029.
🤖 Reviewed with assistance from Claude Code
updateProjectList drops the same entries again on write, so a broken list showed the warning twice in one command. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Short Summary (TL;DR)
Each change to
~/.ddev/project_list.yamlnow happens under a file lock, applied to the list as it is on disk. Concurrent commands no longer drop each other's projects.ddev configno longer writes an entry with an empty name whenomit_project_name_by_defaultis set.The Issue
#9004: each process wrote back the copy of the list it loaded at startup, so a project registered meanwhile was lost.
#9017: the interactive
ddev configclearedapp.Nameto omit it from config.yaml, andWriteConfigthen registered the approot under"". Only the flag path removed that entry. Afterwardddev startfailed with "already contains a project named ''", and everyddev configelsewhere failed. The interactive path needs no concurrency.The flag path had a second route to the same state. It wrote
""and removed it a moment later. Anotherddevcommand that read the list in that moment wrote the entry back, and nothing removed it again. Oneddev configwhile anotherddev configlooped left a permanent""entry in 6 of 20 trials on HEAD, and in 0 of 20 with this PR.How This PR Solves The Issue
globalconfig.updateProjectListtakesproject_list.yaml.lock(gofrs/flock), rereads the file, applies one change, and writes.SetProjectAppRootandRemoveProjectInfouse it, and it drops entries without a name or approot, asReadProjectListdoes. The unusedReservePortsis removed.ReadProjectListreads and sets aside an unparseable file under the same lock.UpdateProjectchecks ports and approot and writes them in one locked step.UpdateGlobalProjectListuses it, so a ports-only entry is never written on its own.UpdateGlobalProjectListskips an empty name, andglobalconfigrefuses one. Bothddev configpaths register the real name afterWriteConfig.""entry, and the next write removes it, so existing broken lists repair themselves.UpdateGlobalConfigrereadsglobal_config.yamlbefore changing one field. The upgrade prompts andddev utility xdebug-diagnoseuse it, so they don't revert a change made during the prompt.Manual Testing Instructions
Use a scratch global directory. Neither test needs Docker.
#9017, empty-name entry:
#9004, lost update. A pre-config hook holds the first
ddev configbetween loading and saving the list:Automated Testing Overview
New tests in
pkg/globalconfig:TestUpdateProjectListKeepsOtherProcessChanges: an add or remove keeps entries that another process wrote after startup.TestConcurrentProjectListWriters: four test-binary processes register 10 projects each, and all 40 remain. With the lock disabled, only 10 remain.TestProjectListEmptyName: an empty name is refused, and an existing""entry is dropped.TestUpdateGlobalConfigKeepsOtherProcessChanges: a field change keeps a value another process wrote.Generated by Claude Code