Skip to content

Conversation

@jasagredo
Copy link
Contributor

@jasagredo jasagredo commented Oct 30, 2025

Double read lock acquisition

We were running an unsafeAcquireReadAccess inside a withReadLock block. If a write lock arrives exactly in between, the second acquisition cannot continue and neither can the write lock, deadlocking the whole node.

This is solved by acquiring the read lock once, and then "transferring its ownership" onto the forker.

Track the read lock in the resource registry

As we then acquire the read lock, we need to make sure it is cleaned up properly in the presence of exceptions, so we put the allocation in the resource registry. However this means that the registry will try to double free if we actually closed the forker. So we use a TVar that contains a releasing action such that it is the null action if we created the forker.

Track the forker in the resource registry

Now we also need to track the forker once opened in the resource registry, for it to be deallocated if an exception comes. However the deallocation logic of the forker was meant to be run only once, hence it was using takeMVar. We now use tryTakeMVar such that if the forker was properly closed, then the release from the resource registry is void.

@jasagredo jasagredo force-pushed the js/fix-double-read-lock branch from 6b07410 to fc27af4 Compare October 30, 2025 14:07
@jasagredo jasagredo force-pushed the js/fix-double-read-lock branch from a152e4d to e1d2758 Compare October 31, 2025 10:18
@jasagredo jasagredo force-pushed the js/fix-double-read-lock branch from e1d2758 to d668ffa Compare October 31, 2025 10:25
@jasagredo jasagredo enabled auto-merge October 31, 2025 10:38
@jasagredo jasagredo self-assigned this Oct 31, 2025
@jasagredo jasagredo moved this to 👀 In review in Consensus Team Backlog Oct 31, 2025
Copy link
Member

@amesgen amesgen left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Maybe we should broaden the scope of #1704 to also (try to) simplify the resource handling of the V1 LedgerDB

@jasagredo jasagredo force-pushed the js/fix-double-read-lock branch from ef34b1b to dc8a26c Compare October 31, 2025 12:09
@jasagredo jasagredo added this pull request to the merge queue Oct 31, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Oct 31, 2025
@jasagredo jasagredo added this pull request to the merge queue Oct 31, 2025
Merged via the queue into cardano-node-10.6-backports with commit 9a2dfcc Oct 31, 2025
15 of 18 checks passed
@jasagredo jasagredo deleted the js/fix-double-read-lock branch October 31, 2025 15:40
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Consensus Team Backlog Oct 31, 2025
github-merge-queue bot pushed a commit that referenced this pull request Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants