fix: serialize concurrent property updates

Concurrent commands for the same app could each read a setting, change it, and write it back, so all of them exited successfully while silently dropping changes made by the others. Updates to app settings are now serialized so every change is kept, and readers never see a partially written value.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-10-21 21:21:57 -04:00
1 parent ba1d49576b
commit 9df45f6a6e
42 files changed
+1698 -642

No files matched your search

+35 -1
View File
@@ -260,7 +260,7 @@ Dokku uses a file-based state system for simplicity and transparency.
Plugin-specific configuration is stored in the property system:
```
/var/lib/dokku/data/<plugin>/<app>/<property>
/var/lib/dokku/config/<plugin>/<app>/<property>
```
Properties are managed via helper functions:
@@ -277,6 +277,40 @@ common.PropertyWrite("git", appName, "deploy-branch", "main")
common.PropertyGet("git", appName, "deploy-branch")
```
Property writes for a given plugin and app are serialized by a lock on that app's property directory, and each write replaces the file atomically, so readers never see a partially written value. The list and map helpers, such as `PropertyListAdd` and `PropertyMapSet`, hold the lock while they read, change, and write a property.
Code that reads a property and writes a value derived from it must hold the lock for the whole operation, or concurrent commands for the same app will overwrite each other's changes:
```go
// Go: update a single list property
common.PropertyListUpdate("my-plugin", appName, "items", func(lines []string) ([]string, error) {
return append(lines, "new-item"), nil
})
// Go: read and write several properties together
common.PropertyLock("my-plugin", appName, func(p *common.LockedProperties) error {
current := common.PropertyGet("my-plugin", appName, "current")
if err := p.Write("previous", current); err != nil {
return err
}
return p.Write("current", "new-value")
})
```
```bash
# Shell
fn-my-plugin-rotate() {
declare desc="moves the current value to previous, expecting the caller to hold the my-plugin property lock"
declare APP="$1" VALUE="$2"
fn-plugin-property-write "my-plugin" "$APP" "previous" "$(fn-plugin-property-get "my-plugin" "$APP" "current")"
fn-plugin-property-write "my-plugin" "$APP" "current" "$VALUE"
}
fn-plugin-property-lock "my-plugin" "$APP" fn-my-plugin-rotate "$APP" "new-value"
```
Inside a `PropertyLock` callback, writes must go through the `LockedProperties` handle, as the public writers take the same lock. Shell callbacks may call the regular `fn-plugin-property-*` helpers.
### Per-App Data
Application-specific data sometimes lives in `$DOKKU_ROOT/<app>/`: