-
Notifications
You must be signed in to change notification settings - Fork 477
Fix invocation timeout when incoming request contains "x-ms-invocation-id" header #10980
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
73c4b86
initial wip
satvu 323630c
add release notes
satvu 6a850fc
resolve comments
satvu cd04a93
Merge branch 'dev' into satvu/fix-invocation-timeout-due-to-header
satvu 9f20a66
fix typo, tests
satvu f636afb
Merge branch 'satvu/fix-invocation-timeout-due-to-header' of https://…
satvu 5fc77c7
Merge branch 'dev' into satvu/fix-invocation-timeout-due-to-header
satvu 4819087
resolve comment
satvu 33b88b8
Merge branch 'satvu/fix-invocation-timeout-due-to-header' of https://…
satvu 9a903df
cleanup
satvu d9681cf
Merge branch 'dev' into satvu/fix-invocation-timeout-due-to-header
satvu 81b8ee4
cleanup
satvu cca4480
Merge branch 'satvu/fix-invocation-timeout-due-to-header' of https://…
satvu 530fe67
rm unused import
satvu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| ### Release notes | ||
|
|
||
| <!-- Please add your release notes in the following format: | ||
| - My change description (#PR) | ||
| --> | ||
| - Memory allocation optimizations in `ScriptStartupTypeLocator.GetExtensionsStartupTypesAsync` (#11012) | ||
| ### Release notes | ||
|
|
||
| <!-- Please add your release notes in the following format: | ||
| - My change description (#PR) | ||
| --> | ||
| - Memory allocation optimizations in `ScriptStartupTypeLocator.GetExtensionsStartupTypesAsync` (#11012) | ||
| - Fix invocation timeout when incoming request contains "x-ms-invocation-id" header (#10980) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
test/WebJobs.Script.Tests/HttpProxyService/DefaultHttpProxyServiceTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.Azure.WebJobs.Script.Description; | ||
| using Microsoft.Azure.WebJobs.Script.Grpc; | ||
| using Microsoft.Extensions.Logging; | ||
| using Moq; | ||
| using Xunit; | ||
| using Yarp.ReverseProxy.Forwarder; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Script.Tests | ||
| { | ||
| public class DefaultHttpProxyServiceTests | ||
| { | ||
| private readonly Mock<IHttpForwarder> _httpForwarderMock; | ||
| private readonly Mock<ILogger<DefaultHttpProxyService>> _loggerMock; | ||
| private readonly DefaultHttpProxyService _proxyService; | ||
|
|
||
| public DefaultHttpProxyServiceTests() | ||
| { | ||
| _httpForwarderMock = new Mock<IHttpForwarder>(); | ||
| _loggerMock = new Mock<ILogger<DefaultHttpProxyService>>(); | ||
| _proxyService = new DefaultHttpProxyService(_httpForwarderMock.Object, _loggerMock.Object); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void StartForwarding_SetsCorrelationHeader() | ||
| { | ||
| var httpContext = new DefaultHttpContext(); | ||
| httpContext.Items.Add(ScriptConstants.AzureFunctionsHttpTriggerContext, new()); | ||
| var invocationId = Guid.NewGuid(); | ||
| var context = new ScriptInvocationContext | ||
| { | ||
| FunctionMetadata = new FunctionMetadata { Name = "TestFunction" }, | ||
| ExecutionContext = new ExecutionContext { InvocationId = invocationId }, | ||
| Inputs = new List<(string Name, DataType Type, object Val)> | ||
| { | ||
| ("req", DataType.String, httpContext.Request) | ||
| }, | ||
| Properties = new Dictionary<string, object>() | ||
| }; | ||
|
|
||
| var httpUri = new Uri("http://localhost"); | ||
|
|
||
| _proxyService.StartForwarding(context, httpUri); | ||
|
|
||
| var httpRequest = (HttpRequest)context.Inputs.First().Val; | ||
| Assert.True(httpRequest.Headers.ContainsKey(ScriptConstants.HttpProxyCorrelationHeader)); | ||
| Assert.Equal(invocationId.ToString(), httpRequest.Headers[ScriptConstants.HttpProxyCorrelationHeader]); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void StartForwarding_OverridesExistingCorrelationHeader() | ||
| { | ||
| var httpContext = new DefaultHttpContext(); | ||
| httpContext.Items.Add(ScriptConstants.AzureFunctionsHttpTriggerContext, new()); | ||
| var invocationId = Guid.NewGuid(); | ||
| var context = new ScriptInvocationContext | ||
| { | ||
| FunctionMetadata = new FunctionMetadata { Name = "TestFunction" }, | ||
| ExecutionContext = new ExecutionContext { InvocationId = invocationId }, | ||
| Inputs = new List<(string Name, DataType Type, object Val)> | ||
| { | ||
| ("req", DataType.String, httpContext.Request) | ||
| }, | ||
| Properties = new Dictionary<string, object>() | ||
| }; | ||
|
|
||
| var httpUri = new Uri("http://localhost"); | ||
| var existingCorrelationId = Guid.NewGuid().ToString(); | ||
| var httpRequest = (HttpRequest)context.Inputs.First().Val; | ||
| httpRequest.Headers[ScriptConstants.HttpProxyCorrelationHeader] = existingCorrelationId; | ||
|
|
||
| _proxyService.StartForwarding(context, httpUri); | ||
| Assert.Equal(invocationId.ToString(), httpRequest.Headers[ScriptConstants.HttpProxyCorrelationHeader]); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.