Skip to content

Remove locking in CursorReadingTask.getState()#5203

Open
mp911de wants to merge 2 commits into
mainfrom
issue/5201
Open

Remove locking in CursorReadingTask.getState()#5203
mp911de wants to merge 2 commits into
mainfrom
issue/5201

Conversation

@mp911de

@mp911de mp911de commented Jun 5, 2026

Copy link
Copy Markdown
Member

CursorReadingTask used a single lock to guard both the lifecycle state and access to the underlying MongoCursor.
As the cursor read happens through a long-polling tryNext() call that can block for up to maxAwaitTime, any concurrent getState() invocation (e.g. via Subscription.isActive()) had to wait for the in-flight poll to complete before it could obtain the lock, contradicting the non-blocking nature of the operation.

We now hold the state in a volatile field and read it without acquiring the lock so that getState() returns immediately regardless of an ongoing cursor read. Lifecycle transitions remain guarded by the lock to keep state changes and cursor handling consistent.

Closes #5201

mp911de added 2 commits June 5, 2026 11:04
CursorReadingTask used a single lock to guard both the lifecycle state and access to the underlying MongoCursor.
As the cursor read happens through a long-polling tryNext() call that can block for up to maxAwaitTime, any concurrent getState() invocation (e.g. via Subscription.isActive()) had to wait for the in-flight poll to complete before it could obtain the lock, contradicting the non-blocking nature of the operation.

We now hold the state in a volatile field and read it without acquiring the lock so that getState() returns immediately regardless of an ongoing cursor read. Lifecycle transitions remain guarded by the lock to keep state changes and cursor handling consistent.

Closes #5201
@mp911de mp911de added the type: bug A general bug label Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subscription.isActive() blocks while change stream cursor long-polls

3 participants