Skip to content

Commit 6f6265b

Browse files
authored
Fixing an issue leading to a race when proxying HTTP requests to the worker. (#10121) (#10122)
1 parent 22a24f2 commit 6f6265b

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
- Update PowerShell worker 7.2 to [4.0.3220](https://github.com/Azure/azure-functions-powershell-worker/releases/tag/v4.0.3220)
1111
- Update PowerShell worker 7.4 to [4.0.3219](https://github.com/Azure/azure-functions-powershell-worker/releases/tag/v4.0.3219)
1212
- Update Azure.Identity to 1.11.0 (#10002)
13+
- 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
@@ -877,6 +877,14 @@ internal async Task SendInvocationRequest(ScriptInvocationContext context)
877877
_executingInvocations.TryAdd(invocationRequest.InvocationId, new(context, _messageDispatcherFactory.Create(invocationRequest.InvocationId)));
878878
_metricsLogger.LogEvent(string.Format(MetricEventNames.WorkerInvoked, Id), functionName: Sanitizer.Sanitize(context.FunctionMetadata.Name));
879879

880+
// If the worker supports HTTP proxying, ensure this request is forwarded prior
881+
// to sending the invocation request to the worker, as this will ensure the context
882+
// is properly set up.
883+
if (IsHttpProxyingWorker && context.FunctionMetadata.IsHttpTriggerFunction())
884+
{
885+
_httpProxyService.StartForwarding(context, _httpProxyEndpoint);
886+
}
887+
880888
await SendStreamingMessageAsync(new StreamingMessage
881889
{
882890
InvocationRequest = invocationRequest
@@ -887,11 +895,6 @@ await SendStreamingMessageAsync(new StreamingMessage
887895
var cancellationCtr = context.CancellationToken.Register(() => SendInvocationCancel(invocationRequest.InvocationId));
888896
context.Properties.Add(ScriptConstants.CancellationTokenRegistration, cancellationCtr);
889897
}
890-
891-
if (IsHttpProxyingWorker && context.FunctionMetadata.IsHttpTriggerFunction())
892-
{
893-
_ = _httpProxyService.ForwardAsync(context, _httpProxyEndpoint);
894-
}
895898
}
896899
catch (Exception invokeEx)
897900
{

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)