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

+28 -4
View File
@@ -15,10 +15,18 @@ import (
// addPortMaps adds port mappings to an app
func addPortMaps(appName string, portMaps []PortMap) error {
return common.PropertyLock("ports", appName, func(p *common.LockedProperties) error {
return addPortMapsWithLock(p, appName, portMaps)
})
}
// addPortMapsWithLock adds port mappings to an app. The caller must hold the
// app's ports property lock.
func addPortMapsWithLock(p *common.LockedProperties, appName string, portMaps []PortMap) error {
allPortMaps := getPortMaps(appName)
allPortMaps = append(allPortMaps, portMaps...)
return setPortMaps(appName, allPortMaps)
return writePortMaps(p, allPortMaps)
}
// clearPorts clears all port mappings for an app
@@ -365,6 +373,14 @@ func parsePortMapString(stringPortMap string) ([]PortMap, error) {
// removePortMaps removes specific port mappings from an app
func removePortMaps(appName string, portMaps []PortMap) error {
return common.PropertyLock("ports", appName, func(p *common.LockedProperties) error {
return removePortMapsWithLock(p, appName, portMaps)
})
}
// removePortMapsWithLock removes specific port mappings from an app. The caller
// must hold the app's ports property lock.
func removePortMapsWithLock(p *common.LockedProperties, appName string, portMaps []PortMap) error {
toRemove := map[string]bool{}
toRemoveByPort := map[int]bool{}
@@ -390,10 +406,10 @@ func removePortMaps(appName string, portMaps []PortMap) error {
}
if len(toSet) == 0 {
return common.PropertyDelete("ports", appName, "map")
return p.Delete("map")
}
return setPortMaps(appName, toSet)
return writePortMaps(p, toSet)
}
// reusesSchemeHostPort returns true if the port maps reuse the same scheme:host-port
@@ -413,6 +429,14 @@ func reusesSchemeHostPort(portMaps []PortMap) error {
// setPortMaps sets the port maps for an app
func setPortMaps(appName string, portMaps []PortMap) error {
return common.PropertyLock("ports", appName, func(p *common.LockedProperties) error {
return writePortMaps(p, portMaps)
})
}
// writePortMaps writes the port maps for an app. The caller must hold the
// app's ports property lock.
func writePortMaps(p *common.LockedProperties, portMaps []PortMap) error {
if err := reusesSchemeHostPort(portMaps); err != nil {
return fmt.Errorf("Error validating port mappings: %s", err)
}
@@ -427,7 +451,7 @@ func setPortMaps(appName string, portMaps []PortMap) error {
}
sort.Strings(value)
return common.PropertyListWrite("ports", appName, "map", value)
return p.ListWrite("map", value)
}
// setProxyPort sets the proxy port for an app
+12 -2
View File
@@ -160,11 +160,21 @@ func TriggerPostCertsRemove(appName string) error {
return err
}
return removePortMaps(appName, filterAppPortMaps(appName, "https", 443))
return common.PropertyLock("ports", appName, func(p *common.LockedProperties) error {
return removePortMapsWithLock(p, appName, filterAppPortMaps(appName, "https", 443))
})
}
// TriggerPostCertsUpdate sets port properties after SSL cert is added
func TriggerPostCertsUpdate(appName string) error {
return common.PropertyLock("ports", appName, func(p *common.LockedProperties) error {
return postCertsUpdateWithLock(p, appName)
})
}
// postCertsUpdateWithLock adds https:443 port maps mirroring the app's http:80
// port maps. The caller must hold the app's ports property lock.
func postCertsUpdateWithLock(p *common.LockedProperties, appName string) error {
port := common.PropertyGet("proxy", appName, "proxy-port")
sslPort := common.PropertyGet("proxy", appName, "proxy-ssl-port")
portMaps := getPortMaps(appName)
@@ -201,7 +211,7 @@ func TriggerPostCertsUpdate(appName string) error {
})
}
if err := addPortMaps(appName, toAdd); err != nil {
if err := addPortMapsWithLock(p, appName, toAdd); err != nil {
return err
}
}