-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Ensuring cancellation of tokens when using GetLinkedCancellationToken(a,b) #55968
Ensuring cancellation of tokens when using GetLinkedCancellationToken(a,b) #55968
Conversation
@MattyLeslie thanks for the contribution.
We don't see any updated tests are they missing? |
@javiercn Sorry I forgot to push! |
@javiercn, may I please request a review for this. |
1 similar comment
@javiercn, may I please request a review for this. |
@MattyLeslie sorry, this wasn't on my radar. We'll take a look by end of week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution, @MattyLeslie, and apologies for the delayed review.
I've made some suggestions that will need to be addressed before this can get merged. If you'd like me to handle those, I'm happy to do so!
using (var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(_streamCancellationToken, cancellationToken)) | ||
{ | ||
return await _pipeReaderStream.ReadAsync(buffer.AsMemory(offset, count), linkedCts.Token); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nice characteristic of the previous implementation was that it didn't allocate a new CancellationTokenSource
if at least one CancellationToken
was not cancelable. It would be good to retain that characteristic if possible.
Assert.True(cts.Token.CanBeCanceled); | ||
Assert.False(cts.IsCancellationRequested); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this validate disposal of the linked CTS created in the ReadAsync()
method? These asserts are acting on the CTS created in this test, which shouldn't be affected by any linked CTS that gets created from it.
Same question applies for the other test.
@MackinnonBuck If you're will to carry it over the line that would be great otherwise I'll address that feedback as soon as I get time. |
…"ReadAsync_ByteArray_DisposesCancellationTokenSource"
d7af27e
to
708c0fd
Compare
1cd9b14
to
844215d
Compare
if (a.CanBeCanceled && b.CanBeCanceled) | ||
{ | ||
return CancellationTokenSource.CreateLinkedTokenSource(a, b).Token; | ||
} | ||
else if (a.CanBeCanceled) | ||
{ | ||
return a; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for this logic disappearing and relying directly on ValueLinkdedCancellationTokenSource.Create
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, I saw it got moved. I thought ValueLinkdedCancellationTokenSource
was a framework class.
Fix HANDLE_LEAK issue by properly disposing
CancellationTokenSource
inRemoteJSDataStream
Summary of the changes
Properly dispose
CancellationTokenSource
inRemoteJSDataStream
to prevent handle leaks.Description
This PR addresses the HANDLE_LEAK issue identified in
RemoteJSDataStream
by ensuring thatCancellationTokenSource
instances are properly disposed of. TheGetLinkedCancellationToken
method was removed, and using statements were added directly within theReadAsync
methods to manage the lifecycle ofCancellationTokenSource
. Additionally, the test cases were updated to validate the correct disposal ofCancellationTokenSource
.Changes Made
GetLinkedCancellationToken
method.ReadAsync
methods for proper disposal ofCancellationTokenSource
.CancellationTokenSource
.Fixes #50676