{{ message }}
Replace .Wait() and .Result with .GetAwaiter().GetResult() in help download#27620
Open
euxaristia wants to merge 2 commits into
Open
Replace .Wait() and .Result with .GetAwaiter().GetResult() in help download#27620euxaristia wants to merge 2 commits into
.Wait() and .Result with .GetAwaiter().GetResult() in help download#27620euxaristia wants to merge 2 commits into
Conversation
…elp download The `.Wait()` and `.Result` methods on `Task` wrap exceptions in `AggregateException` and can cause deadlocks in synchronization contexts. Use `.GetAwaiter().GetResult()` which unwraps the inner exception and avoids synchronization context capture.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the updatable help download path to avoid using Task.Wait() / Task.Result, switching to .GetAwaiter().GetResult() to prevent AggregateException wrapping and reduce deadlock risk in DownloadHelpContentHttpClient and WriteResponseToFile.
Changes:
- Replaced
GetAsync(...).Wait()/.Resultwith.GetAwaiter().GetResult()and adjusted cancellation handling. - Refactored
WriteResponseToFileto remove theWait()+Exceptionpattern in favor of try/catch around the synchronous wait.
Comment on lines
+793
to
+796
Comment on lines
809
to
818
…essage Return false on cancellation (not _stopping) so the caller doesn't treat a canceled download as success. Wrap HttpResponseMessage in using to avoid holding connections.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

PR Summary
Replace
.Wait()and.Resultcalls inDownloadHelpContentandWriteResponseToFilewith.GetAwaiter().GetResult()to avoid deadlock risks andAggregateExceptionwrapping.PR Context
The
.Wait()and.Resultmethods onTaskwrap exceptions inAggregateExceptionand can cause deadlocks in synchronization contexts (e.g., if theSynchronizationContextis captured and the continuation is posted back to a single-threaded context). Using.GetAwaiter().GetResult()unwraps the inner exception and does not capture the synchronization context.In
WriteResponseToFile, the original code also used a redundantcopyStreamOp.Wait()+copyStreamOp.Exceptionpattern. The new code uses a try/catch block for cleaner error handling.PR Checklist