-
Notifications
You must be signed in to change notification settings - Fork 458
Fail executions when worker restarts due to function timeout #10979
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
Open
satvu
wants to merge
13
commits into
dev
Choose a base branch
from
satvu/worker-crash-fix
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
38f7873
initial wip
satvu 9948cc4
release notes
satvu b665344
test cleanup
satvu b7640c9
style cop fix
satvu bb70e8d
update
satvu 526261c
cleanup
satvu 639b3cc
release notes
satvu 145d04a
style change
satvu 20fec92
clean up unused import
satvu 51e9e09
remove exception check
satvu 66501b5
cancel task if no exception
satvu 49d978f
Merge branch 'dev' into satvu/worker-crash-fix
satvu c8cb98c
Merge branch 'dev' into satvu/worker-crash-fix
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,14 +1,15 @@ | ||
### Release notes | ||
|
||
<!-- Please add your release notes in the following format: | ||
- My change description (#PR) | ||
--> | ||
- Improved memory metrics reporting using CGroup data for Linux consumption (#10968) | ||
- Memory allocation optimizations in `RpcWorkerConfigFactory.AddProviders` (#10959) | ||
- Fixing GrpcWorkerChannel concurrency bug (#10998) | ||
- Avoid circular dependency when resolving LinuxContainerLegionMetricsPublisher. (#10991) | ||
- Add 'unix' to the list of runtimes kept when importing PowerShell worker for Linux builds | ||
- Update PowerShell 7.4 worker to 4.0.4206 | ||
- Update Python Worker Version to [4.37.0](https://github.com/Azure/azure-functions-python-worker/releases/tag/4.37.0) | ||
- Add runtime and process metrics. (#11034) | ||
- Add `win-arm64` and `linux-arm64` to the list of PowerShell runtimes; added filter for `osx` RIDs (includes `osx-x64` and `osx-arm64`) (#11013) | ||
### Release notes | ||
|
||
<!-- Please add your release notes in the following format: | ||
- My change description (#PR) | ||
--> | ||
- Improved memory metrics reporting using CGroup data for Linux consumption (#10968) | ||
- Memory allocation optimizations in `RpcWorkerConfigFactory.AddProviders` (#10959) | ||
- Fixing GrpcWorkerChannel concurrency bug (#10998) | ||
- Avoid circular dependency when resolving LinuxContainerLegionMetricsPublisher. (#10991) | ||
- Add 'unix' to the list of runtimes kept when importing PowerShell worker for Linux builds | ||
- Update PowerShell 7.4 worker to 4.0.4206 | ||
- Update Python Worker Version to [4.37.0](https://github.com/Azure/azure-functions-python-worker/releases/tag/4.37.0) | ||
- Add runtime and process metrics. (#11034) | ||
- Add `win-arm64` and `linux-arm64` to the list of PowerShell runtimes; added filter for `osx` RIDs (includes `osx-x64` and `osx-arm64`) (#11013) | ||
- Bug fix that fails current executions when a worker channel restarts (#10979) |
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
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
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
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
using System.Threading.Tasks; | ||
using System.Threading.Tasks.Dataflow; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Azure.WebJobs.Host; | ||
using Microsoft.Azure.WebJobs.Host.Executors.Internal; | ||
using Microsoft.Azure.WebJobs.Script.Config; | ||
using Microsoft.Azure.WebJobs.Script.Description; | ||
|
@@ -549,6 +550,61 @@ public async Task FunctionDispatcher_Restart_ErroredChannels_OnWorkerRestart_Not | |
} | ||
} | ||
|
||
[Fact] | ||
public async Task FunctionDispatcher_RestartOfTimedOutChannels_WebHostFailsCurrentExecutions() | ||
{ | ||
var invocationId = Guid.NewGuid().ToString(); | ||
var mockChannel = new Mock<IRpcWorkerChannel>(MockBehavior.Strict); | ||
var mockJobHostChannelManager = new Mock<IJobHostRpcWorkerChannelManager>(MockBehavior.Strict); | ||
var mockWebHostChannelManager = new Mock<IWebHostRpcWorkerChannelManager>(MockBehavior.Strict); | ||
|
||
SetUpMocksForTimeoutTests(mockWebHostChannelManager, mockJobHostChannelManager, mockChannel, invocationId, true); | ||
|
||
var workerConfig = new RpcWorkerConfig | ||
{ | ||
Description = new RpcWorkerDescription { Language = "test" }, | ||
CountOptions = new WorkerProcessCountOptions { ProcessCount = 1 } | ||
}; | ||
|
||
var dispatcher = GetTestFunctionDispatcher(mockwebHostLanguageWorkerChannelManager: mockWebHostChannelManager, mockJobHostLanguageWorkerChannelManager: mockJobHostChannelManager); | ||
|
||
var result = await dispatcher.RestartWorkerWithInvocationIdAsync(invocationId, new FunctionTimeoutException()); | ||
|
||
Assert.True(result); | ||
mockWebHostChannelManager.Verify(m => m.ShutdownChannelIfExistsAsync( | ||
It.IsAny<string>(), | ||
It.Is<string>(id => id == "testChannelId"), | ||
It.Is<Exception>(ex => ex is FunctionTimeoutException)), | ||
Times.Once); | ||
} | ||
|
||
[Fact] | ||
public async Task FunctionDispatcher_RestartOfTimedOutChannels_JobHostFailsCurrentExecutions() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The WebHost will try to shut down the channel first and fail executions, but in the case that returns false we want to make sure the JobHost attempts to. See here. |
||
{ | ||
var invocationId = Guid.NewGuid().ToString(); | ||
var mockChannel = new Mock<IRpcWorkerChannel>(MockBehavior.Strict); | ||
var mockJobHostChannelManager = new Mock<IJobHostRpcWorkerChannelManager>(MockBehavior.Strict); | ||
var mockWebHostChannelManager = new Mock<IWebHostRpcWorkerChannelManager>(MockBehavior.Strict); | ||
|
||
SetUpMocksForTimeoutTests(mockWebHostChannelManager, mockJobHostChannelManager, mockChannel, invocationId, false); | ||
|
||
var workerConfig = new RpcWorkerConfig | ||
{ | ||
Description = new RpcWorkerDescription { Language = "test" }, | ||
CountOptions = new WorkerProcessCountOptions { ProcessCount = 1 } | ||
}; | ||
|
||
var dispatcher = GetTestFunctionDispatcher(mockwebHostLanguageWorkerChannelManager: mockWebHostChannelManager, mockJobHostLanguageWorkerChannelManager: mockJobHostChannelManager); | ||
|
||
var result = await dispatcher.RestartWorkerWithInvocationIdAsync(invocationId, new FunctionTimeoutException()); | ||
|
||
Assert.True(result); | ||
mockJobHostChannelManager.Verify(m => m.ShutdownChannelIfExistsAsync( | ||
It.Is<string>(id => id == "testChannelId"), | ||
It.Is<Exception>(ex => ex is FunctionTimeoutException)), | ||
Times.Once); | ||
} | ||
|
||
[Fact] | ||
public async Task FunctionDispatcher_Error_WithinThreshold_BucketFills() | ||
{ | ||
|
@@ -713,6 +769,7 @@ private static RpcFunctionInvocationDispatcher GetTestFunctionDispatcher( | |
int maxProcessCountValue = 1, | ||
bool addWebhostChannel = false, | ||
Mock<IWebHostRpcWorkerChannelManager> mockwebHostLanguageWorkerChannelManager = null, | ||
Mock<IJobHostRpcWorkerChannelManager> mockJobHostLanguageWorkerChannelManager = null, | ||
bool throwOnProcessStartUp = false, | ||
TimeSpan? startupIntervals = null, | ||
string runtime = null, | ||
|
@@ -767,6 +824,10 @@ private static RpcFunctionInvocationDispatcher GetTestFunctionDispatcher( | |
{ | ||
testWebHostLanguageWorkerChannelManager = mockwebHostLanguageWorkerChannelManager.Object; | ||
} | ||
if (mockJobHostLanguageWorkerChannelManager != null) | ||
{ | ||
jobHostLanguageWorkerChannelManager = mockJobHostLanguageWorkerChannelManager.Object; | ||
} | ||
|
||
var mockFunctionDispatcherLoadBalancer = new Mock<IRpcFunctionInvocationDispatcherLoadBalancer>(); | ||
mockFunctionDispatcherLoadBalancer.Setup(m => m.GetLanguageWorkerChannel(It.IsAny<IEnumerable<IRpcWorkerChannel>>())) | ||
|
@@ -867,5 +928,35 @@ private void VerifyStartIntervals(TimeSpan from, TimeSpan to, bool ignoreFirstSt | |
Assert.True(diff > from && diff < to, $"Expected startup intervals between {from.TotalMilliseconds}ms and {to.TotalMilliseconds}ms. Actual: {diff.TotalMilliseconds}ms."); | ||
} | ||
} | ||
|
||
private void SetUpMocksForTimeoutTests(Mock<IWebHostRpcWorkerChannelManager> mockWebHostChannelManager, Mock<IJobHostRpcWorkerChannelManager> mockJobHostChannelManager, | ||
Mock<IRpcWorkerChannel> mockChannel, string invocationId, bool webHostShutdownSucceeds) | ||
{ | ||
// Setup the channel managers to return our mock channel | ||
mockWebHostChannelManager.Setup(mockWebHostChannelManager => mockWebHostChannelManager.GetChannels(It.IsAny<string>())) | ||
.Returns(new Dictionary<string, TaskCompletionSource<IRpcWorkerChannel>>()); | ||
mockJobHostChannelManager.Setup(m => m.GetChannels(It.IsAny<string>())) | ||
.Returns(new List<IRpcWorkerChannel> { mockChannel.Object }); | ||
mockJobHostChannelManager.Setup(m => m.GetChannels()) | ||
.Returns(new List<IRpcWorkerChannel> { mockChannel.Object }); | ||
|
||
// Setup the mock channel to indicate it's executing the specified invocation | ||
mockChannel.Setup(c => c.Id).Returns("testChannelId"); | ||
mockChannel.Setup(c => c.IsExecutingInvocation(invocationId)).Returns(true); | ||
mockChannel.Setup(c => c.IsChannelReadyForInvocations()).Returns(true); | ||
|
||
// Set up WebHost ShutdownChannelIfExistsAsync to return false, forcing the JobHost to attempt to shutdown channel | ||
mockWebHostChannelManager.Setup(m => m.ShutdownChannelIfExistsAsync( | ||
It.IsAny<string>(), | ||
It.Is<string>(id => id == "testChannelId"), | ||
It.Is<Exception>(ex => ex is FunctionTimeoutException))) | ||
.ReturnsAsync(webHostShutdownSucceeds); | ||
|
||
// Set up JobHost ShutdownChannelIfExistsAsync to be called with the right exception type | ||
mockJobHostChannelManager.Setup(m => m.ShutdownChannelIfExistsAsync( | ||
It.Is<string>(id => id == "testChannelId"), | ||
It.Is<Exception>(ex => ex is FunctionTimeoutException))) | ||
.ReturnsAsync(!webHostShutdownSucceeds); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When will this function ever return false? Is there is no scenario for it, why is it a bool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked into this - the bool returned also isn't used anywhere (in all references, this method is called with no action taken based on the result). Will refactor.