Skip to content

Remove no sync context scope and add ConfigureAwait(false) - #5225

Merged
NinoFloris merged 5 commits into
npgsql:mainfrom
NinoFloris:remove-no-sync-context-scope
Sep 26, 2023
Merged

NinoFloris merged 5 commits into
npgsql:mainfrom
NinoFloris:remove-no-sync-context-scope

Conversation

@NinoFloris

Copy link
Copy Markdown
Member

Closes #1130

@NinoFloris
NinoFloris force-pushed the remove-no-sync-context-scope branch from 371c320 to 3cc96a3 Compare September 25, 2023 22:23
@NinoFloris
NinoFloris marked this pull request as ready for review September 25, 2023 22:23
@NinoFloris
NinoFloris force-pushed the remove-no-sync-context-scope branch from 3cc96a3 to 2c4c00a Compare September 25, 2023 23:28

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

Looks good! There's some cases of ThrowIfCancelled() in a non-async method, which would produce an exception instead of a cancelled task (see below), as well as some more simplifying inline opportunities.

Important: the project seems to build just fine if a ConfigureAwait(false) is omitted; I think we need to make CA2007 it a warning via .editorconfig (which warnings-as-errors then turns to an error)

Task Write<T>(bool async, T value, string dataTypeName, CancellationToken cancellationToken = default)
{
CheckColumnIndex();
cancellationToken.ThrowIfCancellationRequested();

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.

Careful, if you do this from a non-async method, invoking with a cancelled token causes an OperationCancelledException to be thrown, rather than a cancelled task to be returned (it's subtle but it's there). That's why we currently have a check followed by returning a cancelled task (seems like another analyzer rule that should be there...)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes good catch, I clearly went too fast with the refactor here. (I'm aware of the semantic difference, I authored https://www.nuget.org/packages/Ply after all)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't look like it's fixed

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.

I thought I saw it fixed, maybe some sort of botched commit?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment thread src/Npgsql/NpgsqlCommand.cs Resolved
Comment thread src/Npgsql/NpgsqlRawCopyStream.cs Resolved
Comment thread src/Npgsql/NpgsqlRawCopyStream.cs Resolved
@NinoFloris
NinoFloris force-pushed the remove-no-sync-context-scope branch from 10eaa3e to fdc94fb Compare September 26, 2023 19:03
@NinoFloris
NinoFloris enabled auto-merge (squash) September 26, 2023 19:03
@NinoFloris
NinoFloris merged commit 8d51d1c into npgsql:main Sep 26, 2023
@NinoFloris
NinoFloris deleted the remove-no-sync-context-scope branch September 27, 2023 00:43
Task Write<T>(bool async, T value, NpgsqlDbType npgsqlDbType, CancellationToken cancellationToken = default)
{
CheckColumnIndex();
cancellationToken.ThrowIfCancellationRequested();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't it return Task.FromCanceled just like above?

Task Write<T>(bool async, T value, string dataTypeName, CancellationToken cancellationToken = default)
{
CheckColumnIndex();
cancellationToken.ThrowIfCancellationRequested();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't look like it's fixed

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.

Issues with NoSynchronizationContextScope and Orleans

3 participants