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

fix #6416 #6612

Merged
merged 3 commits into from
Mar 31, 2023
Merged

fix #6416 #6612

merged 3 commits into from
Mar 31, 2023

Conversation

LittleLittleCloud
Copy link
Contributor

We are excited to review your PR.

So we can do the best job, please check:

  • There's a descriptive title that will make sense to other developers some time from now.
  • There's associated issues. All PR's should have issue(s) associated - unless a trivial self-evident change such as fixing a typo. You can use the format Fixes #nnnn in your description to cause GitHub to automatically close the issue(s) when your PR is merged.
  • Your change description explains what the change does, why you chose your approach, and anything else that reviewers should know.
  • You have included any necessary tests in the same PR.

The cause of #6416 is simple: calling Cancel on a disposed CancellationTokenSource. The CancellationTokenSource might be disposed when the handler method get called.

There're three ways to fix this issue

  • disposing object in the right time
  • check if CancellationTokenSource get disposed before canceling
  • don't explicitly dispose CancellationTokenSource and leave it to GC

Eventually I choose the third way because it's challenging to dispose object correctly in multi-thread situation. And checking if an object is diposed before calling seems to verbose.

@@ -248,94 +248,93 @@ public async Task<TrialResult> RunAsync(CancellationToken ct = default)
var parameter = tuner.Propose(trialSettings);
trialSettings.Parameter = parameter;

using (var trialCancellationTokenSource = new CancellationTokenSource())
var trialCancellationTokenSource = new CancellationTokenSource();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only actual change: removing using statement and leave disposing of trialCancellationTokenSource to GC

@LittleLittleCloud
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@codecov
Copy link

codecov bot commented Mar 31, 2023

Codecov Report

Merging #6612 (c4a8655) into main (6002aa8) will decrease coverage by 0.02%.
The diff coverage is n/a.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6612      +/-   ##
==========================================
- Coverage   68.39%   68.37%   -0.02%     
==========================================
  Files        1176     1176              
  Lines      248210   248210              
  Branches    25915    25915              
==========================================
- Hits       169759   169724      -35     
- Misses      71676    71711      +35     
  Partials     6775     6775              
Flag Coverage Δ
Debug 68.37% <ø> (-0.02%) ⬇️
production 62.75% <ø> (-0.02%) ⬇️
test 88.86% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 6 files with indirect coverage changes

@michaelgsharp michaelgsharp merged commit 69b67c4 into dotnet:main Mar 31, 2023
@ghost ghost locked as resolved and limited conversation to collaborators May 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants