Skip to content

fix(mappings): serialise module mapping writes for a system (PPT-2816) - #293

Merged
stakach merged 3 commits into
masterfrom
PPT-2816-serialise-mappings
Sep 30, 2026
Merged

stakach merged 3 commits into
masterfrom
PPT-2816-serialise-mappings

Conversation

@camreeves

Copy link
Copy Markdown
Contributor

What

ControlSystemModules.set_mappings cleared a system's redis hash and then wrote its keys one by one. Two updates of the same system arriving together (on HIO UAT on 24 Sep: a system PUT and the module delete cascade from the same edit, within one second) ran it concurrently, and because each redis call is a fibre switch the two writers interleaved. The hash ended up in an arbitrary order with the Calendar module ahead of the mailers. Drivers pick modules by position in that hash, so the visitor mailer sent through Calendar and the Template Mailer forwarded to itself until core-0 was OOM killed. Full timeline on PPT-2816.

A no-op system update also rewrites the hash (!system.changed? is treated as needing a write), and so does a module rename through ModuleNames, so any two of those overlapping had the same effect.

The writes for a system now take a per-system lock, and the mapping is resolved from the database before the hash is cleared, so the hash is only empty for the time it takes to write it rather than for the duration of the module lookups.

Testing

  • New spec: with the lock for a system held, a second set_mappings for that system is still waiting 300 ms later, and completes with the mapping in the system's order once the lock is released. Run in the compose test runner: 7 examples, 0 failures. With the lock bypassed the same spec fails at the "still waiting" assertion.
  • Type-check of src/core-app.cr clean.

Related

Rollout: the shard change reaches drivers when they are rebuilt against a new driver release; this change ships with the next core release. HIO's core pod also runs at a 2 GiB limit with every driver process inside it, which is what turned the recursion into an outage.

PPT-2816

Two updates of one system could run set_mappings at the same time. Each
cleared the redis hash and wrote its keys one by one, so the two writers
interleaved and the hash ended up in an arbitrary order. Drivers that
pick a module by position in that hash, the mailers in particular, then
picked the wrong module; on HIO UAT this routed every templated email to
the Calendar module and made the Template Mailer send to itself.

The writes for a system now take a per-system lock, and the mapping is
resolved before the hash is cleared so it is only empty while being
written.

PPT-2816
@github-actions github-actions Bot added the type: bug something isn't working label Sep 28, 2026
@camreeves
camreeves marked this pull request as ready for review September 28, 2026 06:50
@camreeves
camreeves requested a review from stakach September 28, 2026 06:50
@stakach

stakach commented Sep 30, 2026

Copy link
Copy Markdown
Member

let's just have a single mapping lock instead of per-system, I don't see contention being high enough to require a lock per-system, also redis writes are serialized anyway so this won't impact performance significantly

@github-actions github-actions Bot added type: bug something isn't working and removed type: bug something isn't working labels Sep 30, 2026

@stakach stakach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stakach

stakach commented Sep 30, 2026

Copy link
Copy Markdown
Member

actually, please fix the CI
Images: minio now uses pgsty/minio:latest and testbucket uses pgsty/mc:latest

@github-actions github-actions Bot added type: bug something isn't working and removed type: bug something isn't working labels Sep 30, 2026
…inio from pgsty

The spec still asked for a lock by system id. The minio and mc images
moved to pgsty/minio and pgsty/mc, and the old names no longer pull,
which failed every CI run before the specs started.

PPT-2816
@stakach
stakach merged commit 87a825a into master Sep 30, 2026
11 checks passed
@stakach
stakach deleted the PPT-2816-serialise-mappings branch September 30, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants