Skip to content

Further improvements for TimeoutCancellationTokenSourceWrapper - #3222

Merged
roji merged 2 commits into
npgsql:mainfrom
Brar:WrapCancellationTokenSourceForResettableTimeouts
Oct 15, 2020
Merged

roji merged 2 commits into
npgsql:mainfrom
Brar:WrapCancellationTokenSourceForResettableTimeouts

Conversation

@Brar

@Brar Brar commented Oct 7, 2020 •

Copy link
Copy Markdown
Member
  1. Add a Reset() method to reset the contained cancellation token source without starting the timeout
  2. Add an optional cancellation token parameter to Start() and Reset() to support creating a linked cancellation token source inside the wrapper

Also add some documentation around the resolution of timeouts

@Brar
Brar requested review from YohDeadfall and roji as code owners October 7, 2020 19:47
@Brar
Brar force-pushed the WrapCancellationTokenSourceForResettableTimeouts branch 2 times, most recently from a5b5ddf to ac730fb Compare October 7, 2020 22:23
Comment thread src/Npgsql/NpgsqlCommand.cs Resolved
Comment thread src/Npgsql/NpgsqlConnector.cs Resolved
Comment thread src/Npgsql/NpgsqlConnector.cs Resolved
Comment thread src/Npgsql/NpgsqlReadBuffer.cs Resolved
1. Add a Reset() method to reset the contained cancellation token source
   without starting the timeout
2. Add an optional cancellation token parameter to Start() and Reset()
   to support creating a linked cancellation token source inside the
   wrapper

Also add some documentation around the resolution of timeouts
@Brar
Brar force-pushed the WrapCancellationTokenSourceForResettableTimeouts branch from 4e6f0f1 to e575edc Compare October 13, 2020 18:27
@Brar
Brar requested a review from roji October 13, 2020 18:36

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

One comment, but otherwise this improves things considerably IMHO. LGTM but I propose to let @vonzshik say if he's OK with merging this before #3191 or prefers for it to come afterwards.

Comment thread src/Npgsql/NpgsqlReadBuffer.cs Resolved
@Brar
Brar force-pushed the WrapCancellationTokenSourceForResettableTimeouts branch from e575edc to 535e495 Compare October 14, 2020 17:49
@roji

roji commented Oct 14, 2020

Copy link
Copy Markdown
Member

Build failures

@Brar

Brar commented Oct 14, 2020 •

Copy link
Copy Markdown
Member Author

Build failures

I know.
Somehow we end up calling Stop() on a disposed wrapper now.
I'm still investigating how this can happen because my latest changes are rather minor and seem unrelated to this.
As I understand it, a NpgsqlReadBuffer that is alive should never contain a disposed wrapper.

@Brar

Brar commented Oct 14, 2020

Copy link
Copy Markdown
Member Author

That was actually a bug in the previous code.
We can't call Stop() in the finally block because NpgsqlConnector.Break() already disposes the containing buffer so we can't operate on it's private fields anymore.

@Brar
Brar force-pushed the WrapCancellationTokenSourceForResettableTimeouts branch from 535e495 to db20b95 Compare October 14, 2020 19:32
@Brar
Brar force-pushed the WrapCancellationTokenSourceForResettableTimeouts branch from db20b95 to 789a65e Compare October 14, 2020 19:50
@Brar

Brar commented Oct 14, 2020

Copy link
Copy Markdown
Member Author

Ok @roji,
I think this is good to go now.
I had to move the TimeoutCancellationTokenSourceWrapper.Stop() calls in NpgsqlReadBuffer and NpgsqlWriteBuffer from the finally block to the try block and the catch block because we call NpgsqlConnector.Break() in the catch block which disposes the buffer and it's contained TimeoutCancellationTokenSourceWrapper.

@roji
roji merged commit e32698f into npgsql:main Oct 15, 2020
@roji

roji commented Oct 15, 2020

Copy link
Copy Markdown
Member

Thanks @Brar!

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.

3 participants