Skip to content

Commit c7323b4

Browse files
committed
Fixing an issue leading to a race when proxying HTTP requests to the worker. (#10121) (#10122)
1 parent 07e9fb1 commit c7323b4

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

release_notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
<!-- Please add your release notes in the following format:
44
- My change description (#PR)
55
-->
6-
- Ensuring non http invocation responses are not processed by IHttpProxyService (#10085)
6+
- 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)