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

Update http proxy to handle client disconnect scenario #10688

Merged
merged 11 commits into from
Jan 9, 2025
8 changes: 8 additions & 0 deletions src/WebJobs.Script.Grpc/Server/RetryProxyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
{
return await base.SendAsync(request, cancellationToken);
}
catch (TaskCanceledException) when (cancellationToken.IsCancellationRequested)
{
_logger.LogInformation("Request was canceled. Stopping retries.");
break;
}
catch (HttpRequestException) when (attemptCount < MaxRetries)
{
_logger.LogWarning("Failed to proxy request to the worker. Retrying in {delay}ms. Attempt {attemptCount} of {maxRetries}.",
Expand All @@ -58,6 +63,9 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
}
}

// If the loop exits without returning, propagate the cancellation
cancellationToken.ThrowIfCancellationRequested();
liliankasem marked this conversation as resolved.
Show resolved Hide resolved

// This should never be reached.
throw null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -36,6 +37,11 @@ public async Task Invoke(HttpContext context)

await _next.Invoke(context);

if (context.RequestAborted.IsCancellationRequested)
liliankasem marked this conversation as resolved.
Show resolved Hide resolved
liliankasem marked this conversation as resolved.
Show resolved Hide resolved
{
context.Response.StatusCode = StatusCodes.Status499ClientClosedRequest;
}

string identities = GetIdentities(context);
_logger.ExecutedHttpRequest(requestId, identities, context.Response.StatusCode, (long)sw.GetElapsedTime().TotalMilliseconds);
}
Expand Down
Loading