Skip to content

Commit b4dc236

Browse files
alexeyzimarevclaude
andcommitted
Add missing ConfigureAwait(false) to prevent sync-over-async deadlocks
Fixes #2083 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 47ca314 commit b4dc236

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/RestSharp/Extensions/HttpResponseExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static async Task<string> GetResponseString(this HttpResponseMessage resp
3232
var encoding = encodingString != null ? TryGetEncoding(encodingString) : clientEncoding;
3333

3434
using var reader = new StreamReader(new MemoryStream(bytes), encoding);
35-
return await reader.ReadToEndAsync();
35+
return await reader.ReadToEndAsync().ConfigureAwait(false);
3636
Encoding TryGetEncoding(string es) {
3737
try {
3838
return Encoding.GetEncoding(es);

src/RestSharp/Response/RestResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async Task<RestResponse> GetDefaultResponse() {
5454
#endif
5555

5656
var bytes = stream == null ? null : await stream.ReadAsBytes(cancellationToken).ConfigureAwait(false);
57-
var content = bytes == null ? null : await httpResponse.GetResponseString(bytes, options.Encoding);
57+
var content = bytes == null ? null : await httpResponse.GetResponseString(bytes, options.Encoding).ConfigureAwait(false);
5858

5959
return new(request) {
6060
Content = content,

src/RestSharp/RestClient.Extensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public async Task<RestResponse<T>> ExecuteAsync<T>(
4545
Ensure.NotNull(request, nameof(request));
4646

4747
var response = await client.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
48-
return await client.Serializers.Deserialize<T>(request, response, client.Options, cancellationToken);
48+
return await client.Serializers.Deserialize<T>(request, response, client.Options, cancellationToken).ConfigureAwait(false);
4949
}
5050

5151
/// <summary>
@@ -172,9 +172,9 @@ [EnumeratorCancellation] CancellationToken cancellationToken
172172
using var reader = new StreamReader(stream);
173173

174174
#if NET7_0_OR_GREATER
175-
while (await reader.ReadLineAsync(cancellationToken) is { } line && !cancellationToken.IsCancellationRequested) {
175+
while (await reader.ReadLineAsync(cancellationToken).ConfigureAwait(false) is { } line && !cancellationToken.IsCancellationRequested) {
176176
#else
177-
while (await reader.ReadLineAsync() is { } line && !cancellationToken.IsCancellationRequested) {
177+
while (await reader.ReadLineAsync().ConfigureAwait(false) is { } line && !cancellationToken.IsCancellationRequested) {
178178
#endif
179179
if (string.IsNullOrWhiteSpace(line)) continue;
180180

0 commit comments

Comments
 (0)