Skip to content

Commit 68220ca

Browse files
committed
lock the config file to prevent parallel access
1 parent 6fbab1e commit 68220ca

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

modules/restish-wrapper/default.nix

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@
3434
fi
3535
}
3636
37-
# Build JSON config using jq
37+
# Build JSON config using jq with file locking to prevent concurrent writes
3838
CONFIG_FILE="$RESTISH_CONFIG_DIR/apis.json"
39+
LOCK_FILE="$RESTISH_CONFIG_DIR/apis.json.lock"
40+
41+
# Acquire exclusive lock (will wait if another process has it)
42+
exec 200>"$LOCK_FILE"
43+
${pkgs.util-linux}/bin/flock 200
3944
${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: svc: ''
4045
${lib.concatStringsSep "\n" (lib.mapAttrsToList (k: v: ''
4146
export HEADER_${sanitizeVarName name}_${sanitizeVarName k}=$(read_value "${v}")
@@ -73,6 +78,9 @@
7378
TEMP_CONFIG=$(mktemp)
7479
${pkgs.envsubst}/bin/envsubst < "$CONFIG_FILE" > "$TEMP_CONFIG"
7580
mv "$TEMP_CONFIG" "$CONFIG_FILE"
81+
82+
# Release lock
83+
exec 200>&-
7684
''}
7785
7886
exec ${pkgs.restish}/bin/restish "$@"

0 commit comments

Comments
 (0)