Skip to content

Commit 03ab073

Browse files
authored
Fixing an issue leading to a race when proxying HTTP requests to the worker. (#10121)
1 parent a77902a commit 03ab073

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

release_notes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
- Update Node.js Worker Version to [3.10.0](https://github.com/Azure/azure-functions-nodejs-worker/releases/tag/v3.10.0) (#9999)
1313
- Update PowerShell worker 7.2 to [4.0.3220](https://github.com/Azure/azure-functions-powershell-worker/releases/tag/v4.0.3220)
1414
- Update PowerShell worker 7.4 to [4.0.3219](https://github.com/Azure/azure-functions-powershell-worker/releases/tag/v4.0.3219)
15-
- Ensuring proxies are disabled, with a warning, when running in Flex Consumption.
15+
- Ensuring proxies are disabled, with a warning, when running in Flex Consumption.
16+
- Fixed an issue leading to a race when invocation responses returned prior to HTTP requests being sent in proxied scenarios.

src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannel.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,14 @@ internal async Task SendInvocationRequest(ScriptInvocationContext context)
890890
_executingInvocations.TryAdd(invocationRequest.InvocationId, new(context, _messageDispatcherFactory.Create(invocationRequest.InvocationId)));
891891
_metricsLogger.LogEvent(string.Format(MetricEventNames.WorkerInvoked, Id), functionName: Sanitizer.Sanitize(context.FunctionMetadata.Name));
892892

893+
// If the worker supports HTTP proxying, ensure this request is forwarded prior
894+
// to sending the invocation request to the worker, as this will ensure the context
895+
// is properly set up.
896+
if (IsHttpProxyingWorker && context.FunctionMetadata.IsHttpTriggerFunction())
897+
{
898+
_httpProxyService.StartForwarding(context, _httpProxyEndpoint);
899+
}
900+
893901
await SendStreamingMessageAsync(new StreamingMessage
894902
{
895903
InvocationRequest = invocationRequest
@@ -900,11 +908,6 @@ await SendStreamingMessageAsync(new StreamingMessage
900908
var cancellationCtr = context.CancellationToken.Register(() => SendInvocationCancel(invocationRequest.InvocationId));
901909
context.Properties.Add(ScriptConstants.CancellationTokenRegistration, cancellationCtr);
902910
}
903-
904-
if (IsHttpProxyingWorker && context.FunctionMetadata.IsHttpTriggerFunction())
905-
{
906-
_ = _httpProxyService.ForwardAsync(context, _httpProxyEndpoint);
907-
}
908911
}
909912
catch (Exception invokeEx)
910913
{

src/WebJobs.Script.Grpc/Server/DefaultHttpProxyService.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public async Task EnsureSuccessfulForwardingAsync(ScriptInvocationContext contex
6666
}
6767
}
6868

69-
public Task ForwardAsync(ScriptInvocationContext context, Uri httpUri)
69+
public void StartForwarding(ScriptInvocationContext context, Uri httpUri)
7070
{
7171
ArgumentNullException.ThrowIfNull(context);
7272

@@ -89,8 +89,6 @@ public Task ForwardAsync(ScriptInvocationContext context, Uri httpUri)
8989

9090
var forwardingTask = _httpForwarder.SendAsync(httpContext, httpUri.ToString(), _messageInvoker, _forwarderRequestConfig).AsTask();
9191
context.Properties.Add(ScriptConstants.HttpProxyTask, forwardingTask);
92-
93-
return forwardingTask;
9492
}
9593
}
9694
}

src/WebJobs.Script.Grpc/Server/IHttpProxyService.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ public interface IHttpProxyService
1111
{
1212
Task EnsureSuccessfulForwardingAsync(ScriptInvocationContext context);
1313

14-
Task ForwardAsync(ScriptInvocationContext context, Uri httpUri);
14+
/// <summary>
15+
/// Initiates a request forward and updates the current context to track forwarding operation.
16+
/// </summary>
17+
/// <param name="context">The <see cref="ScriptInvocationContext"/> for the HTTP invocation.</param>
18+
/// <param name="httpUri">The target URI used for forwarding.</param>
19+
void StartForwarding(ScriptInvocationContext context, Uri httpUri);
1520
}
1621
}

0 commit comments

Comments
 (0)