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:
42 files changed
+1698
-642
No files matched your search
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/proxy/functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
@@ -32,12 +33,7 @@ cmd-proxy-labels-add() {
|
||||
[[ -z "$PASSED_LABEL_VALUE" ]] && dokku_log_fail "Please specify a value for the container label"
|
||||
verify_app_name "$APP"
|
||||
|
||||
local proxy_labels_file_path="$(fn-proxy-get-labels-file-path "$PROXY" "$APP")"
|
||||
touch "$proxy_labels_file_path"
|
||||
cmd-proxy-labels-remove "$PROXY" "$APP" "$PASSED_LABEL_NAME" >/dev/null
|
||||
echo "${PASSED_LABEL_NAME}=${PASSED_LABEL_VALUE}" >>"$proxy_labels_file_path"
|
||||
local all_proxy_labels="$(<"$proxy_labels_file_path")"
|
||||
echo -e "${all_proxy_labels}" | sed '/^$/d' | sort -u >"$proxy_labels_file_path"
|
||||
fn-plugin-property-lock "$PROXY" "$APP" fn-proxy-labels-add "$PROXY" "$APP" "$PASSED_LABEL_NAME" "$PASSED_LABEL_VALUE"
|
||||
}
|
||||
|
||||
cmd-proxy-labels-remove() {
|
||||
@@ -55,8 +51,5 @@ cmd-proxy-labels-remove() {
|
||||
return
|
||||
fi
|
||||
|
||||
local all_proxy_labels="$(<"$proxy_labels_file_path")"
|
||||
local escaped_label_name="$(fn-proxy-escape-extended-sed "$PASSED_LABEL_NAME")"
|
||||
local all_proxy_labels="$(echo -e "${all_proxy_labels}" | sed -E "s/^${escaped_label_name}=.*\$//")"
|
||||
echo -e "${all_proxy_labels}" | sed '/^$/d' | sort -u >"$proxy_labels_file_path"
|
||||
fn-plugin-property-lock "$PROXY" "$APP" fn-proxy-labels-remove "$PROXY" "$APP" "$PASSED_LABEL_NAME"
|
||||
}
|
||||
@@ -56,3 +56,57 @@ fn-proxy-show-label() {
|
||||
|
||||
echo "$proxy_label_value"
|
||||
}
|
||||
|
||||
fn-proxy-labels-add() {
|
||||
declare desc="adds a container label for the specified proxy, expecting the caller to hold the proxy property lock"
|
||||
declare PROXY="$1" APP="$2" LABEL_NAME="$3" LABEL_VALUE="$4"
|
||||
local proxy_labels_file_path="$(fn-proxy-get-labels-file-path "$PROXY" "$APP")"
|
||||
local all_proxy_labels=""
|
||||
|
||||
if [[ -s "$proxy_labels_file_path" ]]; then
|
||||
all_proxy_labels="$(fn-proxy-labels-without "$proxy_labels_file_path" "$LABEL_NAME")"
|
||||
fi
|
||||
|
||||
all_proxy_labels="${all_proxy_labels}"$'\n'"${LABEL_NAME}=${LABEL_VALUE}"
|
||||
echo -e "${all_proxy_labels}" | sed '/^$/d' | sort -u | fn-proxy-write-labels-file "$proxy_labels_file_path"
|
||||
}
|
||||
|
||||
fn-proxy-labels-remove() {
|
||||
declare desc="removes a container label for the specified proxy, expecting the caller to hold the proxy property lock"
|
||||
declare PROXY="$1" APP="$2" LABEL_NAME="$3"
|
||||
local proxy_labels_file_path="$(fn-proxy-get-labels-file-path "$PROXY" "$APP")"
|
||||
|
||||
if [[ ! -s "$proxy_labels_file_path" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
fn-proxy-labels-without "$proxy_labels_file_path" "$LABEL_NAME" | fn-proxy-write-labels-file "$proxy_labels_file_path"
|
||||
}
|
||||
|
||||
fn-proxy-labels-without() {
|
||||
declare desc="prints the sorted labels in a proxy labels file without the named label"
|
||||
declare LABELS_FILE="$1" LABEL_NAME="$2"
|
||||
local all_proxy_labels="$(<"$LABELS_FILE")"
|
||||
local escaped_label_name="$(fn-proxy-escape-extended-sed "$LABEL_NAME")"
|
||||
|
||||
echo -e "${all_proxy_labels}" | sed -E "s/^${escaped_label_name}=.*\$//" | sed '/^$/d' | sort -u
|
||||
}
|
||||
|
||||
fn-proxy-write-labels-file() {
|
||||
declare desc="atomically replaces a proxy labels file with the contents of stdin"
|
||||
declare LABELS_FILE="$1"
|
||||
local tmp_file
|
||||
|
||||
tmp_file="$(mktemp "$(dirname "$LABELS_FILE")/.labels.XXXXXX")"
|
||||
if ! cat >"$tmp_file"; then
|
||||
rm -f "$tmp_file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -f "$LABELS_FILE" ]]; then
|
||||
chmod --reference="$LABELS_FILE" "$tmp_file"
|
||||
else
|
||||
chmod 0644 "$tmp_file"
|
||||
fi
|
||||
mv -f "$tmp_file" "$LABELS_FILE"
|
||||
}
|
||||
Reference in new issue
Block a user