jbonofre opened a new pull request, #2897:
URL: https://github.com/apache/karaf/pull/2897

   ## Summary
   
   Fixes #2805.
   
   `FeatureConfigInstaller.updateExistingConfig()` (used both for the `append` 
and `override` config flows) read the existing cfg file, merged in the new 
properties in memory, then wrote the result **directly back to the target 
file** (`properties.save(cfgFile)` / `Configurations.buildWriter().build(new 
FileWriter(cfgFile))...`).
   
   Calling `cfg.update(...)` just before that write also triggers Configuration 
Admin to notify its persistence manager (fileinstall), which persists the very 
same configuration to the very same cfg file on the CM Event Dispatcher thread. 
With two unsynchronized, non-atomic writers hitting the same file at once, the 
writes can interleave and corrupt the file (as shown in the issue, where lines 
from the old file content bleed into the newly written content).
   
   The "file doesn't exist yet" path already avoids this by writing to a temp 
file and renaming it atomically into place (KARAF-7389 / #1489), but that fix 
didn't cover the "file already exists" path exercised by `append`/`override`. 
This PR applies the same temp-file + atomic rename pattern to 
`updateExistingConfig()`, for both the properties and JSON formats, so a 
concurrent reader/writer can only ever observe a fully-old or fully-new file, 
never a torn one.
   
   ## Test plan
   
   - [x] `mvn -pl features/core test` — all existing tests pass (139 tests)
   - [x] Added 
`FeatureConfigInstallerTest#testUpdateExistingConfigWritesAtomically`, which 
exercises `updateExistingConfig()` against a pre-existing cfg file and asserts 
the merged content is correct and no leftover `.tmp` file remains after the 
rename


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to