Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check cancellation token at start of WaitAsync() #2507

Merged
merged 1 commit into from
Jun 29, 2019

Conversation

roji
Copy link
Member

@roji roji commented Jun 26, 2019

Otherwise passing a cancelled token makes WaitAsync() crash.

Note that a race condition still exists if the token is cancelled after our check but before WaitAsync starts its job.

Fixes #2506

The fix for dev will be part of #2443

Copy link
Contributor

@YohDeadfall YohDeadfall left a comment

Choose a reason for hiding this comment

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

Looks good.

src/Npgsql/NpgsqlConnector.cs Outdated Show resolved Hide resolved
@@ -1228,6 +1228,9 @@ public bool Wait(int timeout)
[PublicAPI]
public Task WaitAsync(CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
return PGUtil.CancelledTask;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should Task.FromCanceled(cancellationToken) be used here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately it doesn't exist in net45 which is targeted in Npgsql 4.0... The equivalent for dev is using Task.FromCanceled() (#2443).

Otherwise passing a cancelled token makes WaitAsync() crash.
Note that a race condition still exists if the token is cancelled
after our check but before WaitAsync starts its job.

Fixes npgsql#2506
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.

2 participants