Skip to content

Fix sending cancellation request if it's requested while reading prepended responses - #5774

Merged
vonzshik merged 3 commits into
mainfrom
5191-cancel-after-prepended-response-fix
Sep 10, 2024
Merged

vonzshik merged 3 commits into
mainfrom
5191-cancel-after-prepended-response-fix

Conversation

@vonzshik

@vonzshik vonzshik commented Jul 1, 2024

Copy link
Copy Markdown
Contributor

Fixes #5191

Let's see what CI thinks first.

@vonzshik
vonzshik requested a review from roji as a code owner July 1, 2024 15:43
@vonzshik

vonzshik commented Jul 2, 2024

Copy link
Copy Markdown
Contributor Author

Surprisingly, everything works and CI is green (even the new test) 🐝

Comment thread src/Npgsql/Internal/NpgsqlConnector.cs Resolved
Comment thread src/Npgsql/Internal/NpgsqlConnector.cs Resolved
Comment thread src/Npgsql/Internal/NpgsqlConnector.cs Resolved
@vonzshik
vonzshik force-pushed the 5191-cancel-after-prepended-response-fix branch from f1a26cf to 79268fe Compare July 26, 2024 14:08

@NinoFloris NinoFloris 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.

Approved, thanks for writing the test against the mock.

// Set the flag first before waiting on ReadingPrependedMessagesMRE.
// That way we're making sure that in case we're racing with ReadingPrependedMessagesMRE.Set
// that it's going to read the new value of the flag and request cancellation
_userCancellationRequested = true;

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.

Nit: after doing a quick search I see the field is marked volatile. It would help comprehension if we use Volatile.Write/Read throughout instead/additionally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sadly, we can't do both:

image

I'm OK with using Volatile.Read/Write, but let's do that in a separate PR and globally.

Comment thread src/Npgsql/Internal/NpgsqlConnector.cs Resolved
Comment thread src/Npgsql/Internal/NpgsqlConnector.cs Resolved
PerformDelayedUserCancellation();
}
catch (Exception e)
{

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.

Should we want to remove

ReadingPrependedMessagesMRE.Set();
from Break? It doesn't seem to serve a purpose, as no method is actually waiting on the MRE.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unless I'm missing something it's already done?

@vonzshik
vonzshik enabled auto-merge (squash) September 10, 2024 13:59
@vonzshik
vonzshik merged commit 8473d72 into main Sep 10, 2024
@vonzshik
vonzshik deleted the 5191-cancel-after-prepended-response-fix branch September 10, 2024 14:02
vonzshik added a commit that referenced this pull request Sep 10, 2024
vonzshik added a commit that referenced this pull request Sep 10, 2024
vonzshik added a commit that referenced this pull request Sep 10, 2024
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.

Command.Cancel() is not honored if invoked immediately after execution

2 participants