Skip to content

fix(llo): skip locked rows in transmission reaper - #24114

Open
kalverra wants to merge 1 commit into
developfrom
fix/llo-transmit-queue-deadlock
Open

kalverra wants to merge 1 commit into
developfrom
fix/llo-transmit-queue-deadlock

Conversation

@kalverra

Copy link
Copy Markdown
Collaborator

Problem

Postgres reports 40P01 deadlock detected on llo_mercury_transmit_queue inside single LLO nodes. Three delete paths lock overlapping rows in different orders:

  • Delete in chainlink-data-streams removes rows by transmission_hash (primary key order).
  • Prune in chainlink-data-streams walks the oldest rows by (don_id, server_url, seq_nr).
  • This PR's transmissionReaper deletes by inserted_at (reapStale) or by don_id (reapOrphaned).

Run concurrently, any two of them can hold locks on rows the other wants, and Postgres kills one. Delete retries with backoff, so the damage is latency and flaky LLO tests rather than an outage.

Fix

Select the reaper's candidate rows with FOR UPDATE SKIP LOCKED. Reaping is best-effort, so skipping a row that is being deleted right now is fine; a later batch or the next reap cycle picks it up.

This also bumps chainlink-data-streams to the commit that fixes the same pattern in Prune (smartcontractkit/chainlink-data-streams#281).

Tests

  • Test_TransmissionReaper_SkipsRowsLockedByDelete holds a row lock in one session and asserts the reaper returns without waiting, for both the stale and orphaned paths. Without the fix it fails with 55P03 lock timeout.
  • Added pgtest.NewIndependentSqlxSessions so a test can hold locks on one real session while another contends for them.

go test ./core/services/llo/ ./core/internal/testutils/pgtest/ and go test ./core/services/llo/ -race -run Test_TransmissionReaper -count=3 pass.

Notes

  • The local pre-push hook was bypassed because it leaks GIT_DIR into tools/release/release-changelog/internal/engine temp repos; those tests pass when run directly and are unrelated to this change.
  • Acceptance still worth running on a quiet machine: make test ARGS="diagnose --iterations 10 -- ./core/services/ocr2/plugins/llo/ -timeout 2m" should show zero 40P01.

The reaper deletes stale and orphaned rows from
llo_mercury_transmit_queue by inserted_at while the data-streams ORM's
Delete removes them by transmission_hash. Run concurrently, the two can
hold locks on rows the other wants and Postgres reports 40P01.

Select the candidate rows with FOR UPDATE SKIP LOCKED. Reaping is
best-effort, so skipping a row that is being deleted right now is fine;
it is picked up by a later batch or the next reap cycle.

Also bump chainlink-data-streams, which fixes the same pattern in Prune.
@kalverra
kalverra requested review from a team as code owners October 30, 2026 16:49
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for adding a CODEOWNERS file - @kalverra.

@github-actions

Copy link
Copy Markdown
Contributor

✅ No conflicts with other open PRs targeting develop

@github-actions

Copy link
Copy Markdown
Contributor

I see you updated files related to core. Please run make gocs in the root directory to add a changeset as well as in the text include at least one of the following tags:

  • #added For any new functionality added.
  • #breaking_change For any functionality that requires manual action for the node to boot.
  • #bugfix For bug fixes.
  • #changed For any change to the existing functionality.
  • #db_update For any feature that introduces updates to database schema.
  • #deprecation_notice For any upcoming deprecation functionality.
  • #internal For changesets that need to be excluded from the final changelog.
  • #nops For any feature that is NOP facing and needs to be in the official Release Notes for the release.
  • #removed For any functionality/config that is removed.
  • #updated For any functionality that is updated.
  • #wip For any change that is not ready yet and external communication about it should be held off till it is feature complete.

@trunk-io

trunk-io Bot commented Oct 30, 2026

Copy link
Copy Markdown

Static Badge   Static Badge   Static Badge

Failed Test Failure Summary Logs
TestIntegration_LLO_aggregation_fault_tolerance/floor_of_1_admits_an_under-observed_stream The LLO aggregation fault-tolerance integration test failed, but the provided log is truncated before the underlying error is shown. Logs ↗︎
TestIntegration_LLO_aggregation_fault_tolerance The integration test for LLO aggregation fault tolerance failed, but the log provides no error details. Logs ↗︎

View Full Report ↗︎ ⋅ Docs

This branch has not been deployed

No deployments
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