Prevent duplicate relation count queries - #5717
Open
ydah wants to merge 1 commit into
Open
Conversation
rmosolgo
reviewed
Aug 28, 2026
rmosolgo
left a comment
Owner
There was a problem hiding this comment.
LGTM, but I think it needs one change now from a fix on master.
I haven't seen Monitor before -- what's the advantage over Mutex?
ydah
force-pushed
the
avoid-duplicate-relation-counts
branch
2 times, most recently
from
August 29, 2026 23:30
969e7bf to
8be8baf
Compare
ydah
force-pushed
the
avoid-duplicate-relation-counts
branch
from
August 29, 2026 23:36
8be8baf to
8d34406
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This follows up on #5708, which prevents concurrent Fibers from loading the same relation page more than once.
RelationConnection#limited_nodesremains independently memoized outside that lock. Withlast:pagination and no existing relation limit, it callsrelation_count(sliced_nodes). If that query yields, another Fiber can enter the same@limited_nodes ||= ...block before the first one finishes.Under
AsyncDataloader, this can happen when connection fields resolve separately:edgesornodescallsload_nodespageInfo.hasPreviousPagecallslimited_nodesdirectlyBoth Fibers can therefore issue the same
COUNTquery.Before this change, the relation is counted twice. After this change, it is counted once.
This PR protects both limited_nodes construction and the final node load with the same Monitor. Monitor is reentrant, so load_nodes can safely call limited_nodes while holding it without risking ThreadError: deadlock; recursive locking.
The synchronization is only used with AsyncDataloader; other dataloaders retain the existing unsynchronized path and its current overhead.