Handle read-only config file gracefully in Docker Swarm#157
Open
mherman22 wants to merge 1 commit into
Open
Conversation
updateConfigFile() calls fs.writeFile on the config JSON file after updating the in-memory config via config.set(). In Docker Swarm, config files are mounted read-only, so the write fails and throw err crashes the entire process. Change to: - Keep config.set() for in-memory state (always works) - Log a warning instead of crashing if fs.writeFile fails - Also handle the case where require(configFile) fails The in-memory config remains correct for the duration of the process. On restart, the config file is re-read from the Docker config mount, so values like lastFHIR2ESSync will reset — but this is expected behavior in immutable infrastructure. Fixes intrahealth#139
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In Docker Swarm, config files are mounted as read-only Docker configs. When
updateConfigFile()ingeneralMixin.jstries to write back to the config file (e.g., to updatesync.lastFHIR2ESSyncafter an ES re-index),fs.writeFilefails andthrow erron line 53 crashes the entire process.This affects any deployment using Docker Swarm or Kubernetes where config files are immutable.
Fix
config.set()still updates the in-memory config (always works, keeps runtime state correct)fs.writeFilefailure now logs a warning instead of crashingrequire(configFile)failure is also handled (in case the file is inaccessible)The in-memory config remains correct for the duration of the process. On restart, the mounted config file is re-read — so values like
lastFHIR2ESSyncwill reset to whatever is in the Docker config, which means the next startup will do a full ES re-sync from that timestamp. This is expected behavior in immutable infrastructure.Fixes #139