Skip to content

fix: lock and reread project_list.yaml on every change, never register an empty project name, fixes #9004, fixes #9017 - #9020

Merged
rfay merged 3 commits into
ddev:mainfrom
rfay:20261027_rfay_project_list_lock
Oct 28, 2026
Merged

rfay merged 3 commits into
ddev:mainfrom
rfay:20261027_rfay_project_list_lock

Conversation

@rfay

@rfay rfay commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

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

#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 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. 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. Another ddev command that read the list in that moment wrote the entry back, and nothing removed it again. One ddev config while another ddev config looped 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.updateProjectList takes project_list.yaml.lock (gofrs/flock), rereads the file, applies one change, and writes. SetProjectAppRoot and RemoveProjectInfo use it, and it drops entries without a name or approot, as ReadProjectList does. The unused ReservePorts is removed. 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 for the rest of that ddev process. 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.

ddev utility download-ddev --pr 9020
export PATH="$HOME/tmp/ddev-download-ddev/pr-9020:$PATH"
export DDEV_XDG_CONFIG_HOME=~/tmp/race-xdg
mkdir -p ~/tmp/race-xdg ~/tmp/race/a ~/tmp/race/b ~/tmp/race/c

#9017, empty-name entry:

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 '"":'

#9004, lost update. A pre-config hook holds the first ddev config between loading and saving the list:

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.

Generated by Claude Code

@rfay
rfay requested a review from a team as a code owner October 27, 2026 13:48
@rfay
rfay marked this pull request as draft October 27, 2026 13:49
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Download this PR's build for your OS and architecture with:

ddev utility download-ddev --pr 9020

Or download the artifact for your OS and architecture directly:

See Testing a PR.

Open in GitHub Codespaces

…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
@rfay
rfay force-pushed the 20261027_rfay_project_list_lock branch from 659d543 to fc99a41 Compare October 27, 2026 16:16
@rfay
rfay marked this pull request as ready for review October 28, 2026 16:04

@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.

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

Comment thread pkg/globalconfig/global_config_test.go Outdated
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))

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.

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:

Suggested change
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)

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.

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?

Comment thread pkg/globalconfig/global_config.go Outdated
if err != nil {
return err
}
// Entries without an approot stay, since ReservePorts writes them.

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.

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.

Comment thread pkg/globalconfig/global_config.go Outdated
return nil
}

// projectListLockTimeout is a var so tests can shorten it.

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.

Small thing: this is not true, no test changes projectListLockTimeout.

Comment thread cmd/ddev/cmd/config.go
}

// Restore the name and update global project list with correct name
// WriteConfig doesn't register an empty name, so register the real one.

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.

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 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.

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]>

@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.

@rfay
rfay merged commit bb67925 into ddev:main Oct 28, 2026
40 of 44 checks passed
@rfay
rfay deleted the 20261027_rfay_project_list_lock branch October 28, 2026 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

3 participants