Skip to content

[6/15] Make settings resolution thread-safe - #159

Open
UnknownJoe796 wants to merge 1 commit into
version-5.3from
v53/settings-thread-safety
Open

[6/15] Make settings resolution thread-safe#159
UnknownJoe796 wants to merge 1 commit into
version-5.3from
v53/settings-thread-safety

Conversation

@UnknownJoe796

Copy link
Copy Markdown
Contributor

Concurrent first-touch of a setting could resolve it more than once. Resolution
is now guarded.

Note for reviewers: this lands the ConcurrentHashMap form. The
access-logging PR later in the stack refines it to a @Volatile
copy-on-write map. The fix is real either way; only the implementation evolves.
Flagged so the later change is not a surprise.

Comment thread core/src/main/kotlin/com/lightningkite/lightningserver/settings/ServerSettings.kt Outdated
@UnknownJoe796
UnknownJoe796 force-pushed the v53/settings-thread-safety branch from b2759a2 to ed1d009 Compare July 29, 2026 22:54
Concurrent first-touch of a setting could resolve it more than once.
Transformed results are now published as an immutable snapshot: reads are
lock-free (once a setting is resolved, an immutable Map makes it visible
for good via a @volatile field), and writes replace the whole map under a
single lock (copy-on-write) -- cheap, since each setting resolves at most
once, and in production every setting is pre-resolved single-threaded
during ready(). A single reentrant lock guards transformation because a
setting's getter may resolve its own dependencies by calling get() again
on the same thread; per-setting locks could deadlock on mutually-dependent
settings instead.

(cherry picked from commit ed1d009)
@UnknownJoe796
UnknownJoe796 force-pushed the v53/settings-thread-safety branch from ed1d009 to 4067167 Compare July 30, 2026 02:19
@UnknownJoe796
UnknownJoe796 changed the base branch from v53/auth-backoff to version-5.3 July 30, 2026 02:24
@UnknownJoe796

Copy link
Copy Markdown
Contributor Author

Much better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant