mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
A Stack is shared state: it lives in the service's concurrent map and is handed to every request that names it while the operation executor provisions it, but its collections were plain LinkedHashMaps and an ArrayList mutated outside any lock. DescribeStackEvents copied the event list while a running ExecuteChangeSet appended to it (41 addEvent sites), resources were put and removed while DescribeStackResources walked them, and DeleteChangeSet removed from the change-set map under nothing. The model now owns its thread safety: synchronized maps over LinkedHashMap, so the insertion order the XML responses reproduce survives; a CopyOnWriteArrayList for the append-mostly event log; setters that wrap whatever Jackson or the service hands in; and *Snapshot() accessors that copy under the map's monitor. Jackson serializes through the snapshots under the same property names, so persisting a stack mid-deploy no longer races the deploy and the stored shape is unchanged. Every iterating site in CloudFormationService and the query handler reads a snapshot; the one removeIf on the change-set map runs under its monitor. #3564 had already made the change-set claim atomic; #2473 carried this shape but was closed after a broken rebase. A whole-map replace is one step too. clear() and putAll() are two separately locked calls on a synchronized map, so a snapshot between them copied an empty map: a DescribeStacks mid-update reporting no Outputs. Stack's replace* methods hold the map's monitor across the pair, and the nine clear/putAll sites (parameters, the update's outputs, exports and export names, both rollback restores) go through them. Closes #2419