Skip to content

Commit 1f90fc4

Browse files
committed
update
1 parent aa77294 commit 1f90fc4

File tree

5 files changed

+12
-19
lines changed

5 files changed

+12
-19
lines changed

src/WebJobs.Script.WebHost/WebScriptHostExceptionHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public async Task OnTimeoutExceptionAsync(ExceptionDispatchInfo exceptionInfo, T
5454
{
5555
_logger.LogWarning($"A function timeout has occurred. Restarting worker process executing invocationId '{timeoutException.InstanceId}'.", exceptionInfo.SourceException);
5656
// If invocation id is not found in any of the workers => worker is already disposed. No action needed.
57-
await functionInvocationDispatcher.RestartWorkerWithInvocationIdAsync(timeoutException.InstanceId.ToString());
57+
await functionInvocationDispatcher.RestartWorkerWithInvocationIdAsync(timeoutException.InstanceId.ToString(), timeoutException);
5858
_logger.LogWarning("Restart of language worker process(es) completed.", exceptionInfo.SourceException);
5959
}
6060
else

src/WebJobs.Script/Workers/Http/HttpFunctionInvocationDispatcher.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public Task ShutdownAsync()
206206
return Task.CompletedTask;
207207
}
208208

209-
public Task<bool> RestartWorkerWithInvocationIdAsync(string invocationId)
209+
public Task<bool> RestartWorkerWithInvocationIdAsync(string invocationId, Exception exception = default)
210210
{
211211
// Since there's only one channel for httpworker
212212
DisposeAndRestartWorkerChannel(_httpWorkerChannel.Id);

src/WebJobs.Script/Workers/IFunctionInvocationDispatcher.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public interface IFunctionInvocationDispatcher : IDisposable
2323

2424
Task ShutdownAsync();
2525

26-
Task<bool> RestartWorkerWithInvocationIdAsync(string invocationId);
26+
Task<bool> RestartWorkerWithInvocationIdAsync(string invocationId, Exception exception = default);
2727

2828
Task StartWorkerChannel();
2929

src/WebJobs.Script/Workers/Rpc/FunctionRegistration/RpcFunctionInvocationDispatcher.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ public void Dispose()
677677
Dispose(true);
678678
}
679679

680-
public async Task<bool> RestartWorkerWithInvocationIdAsync(string invocationId)
680+
public async Task<bool> RestartWorkerWithInvocationIdAsync(string invocationId, Exception e = default)
681681
{
682682
// Dispose and restart errored channel with the particular invocation id
683683
var channels = await GetInitializedWorkerChannelsAsync();
@@ -686,7 +686,7 @@ public async Task<bool> RestartWorkerWithInvocationIdAsync(string invocationId)
686686
if (channel.IsExecutingInvocation(invocationId))
687687
{
688688
_logger.LogDebug($"Restarting channel with workerId: '{channel.Id}' that is executing invocation: '{invocationId}' and timed out.");
689-
await DisposeAndRestartWorkerChannel(_workerRuntime, channel.Id, new TimeoutException($"Executing invocation `{invocationId}` timed out"));
689+
await DisposeAndRestartWorkerChannel(_workerRuntime, channel.Id, e);
690690
return true;
691691
}
692692
}

test/WebJobs.Script.Tests/Workers/Rpc/RpcFunctionInvocationDispatcherTests.cs

+7-14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Threading.Tasks;
1010
using System.Threading.Tasks.Dataflow;
1111
using Microsoft.AspNetCore.Hosting;
12+
using Microsoft.Azure.WebJobs.Host;
1213
using Microsoft.Azure.WebJobs.Host.Executors.Internal;
1314
using Microsoft.Azure.WebJobs.Script.Config;
1415
using Microsoft.Azure.WebJobs.Script.Description;
@@ -559,25 +560,21 @@ public async Task FunctionDispatcher_RestartOfTimedOutChannels_WebHostFailsCurre
559560

560561
SetUpMocksForTimeoutTests(mockWebHostChannelManager, mockJobHostChannelManager, mockChannel, invocationId, true);
561562

562-
// Setup for initialization of a new channel
563563
var workerConfig = new RpcWorkerConfig
564564
{
565565
Description = new RpcWorkerDescription { Language = "test" },
566566
CountOptions = new WorkerProcessCountOptions { ProcessCount = 1 }
567567
};
568568

569-
// Create the dispatcher with our mocks
570569
var dispatcher = GetTestFunctionDispatcher(mockwebHostLanguageWorkerChannelManager: mockWebHostChannelManager, mockJobHostLanguageWorkerChannelManager: mockJobHostChannelManager);
571570

572-
// Act
573-
var result = await dispatcher.RestartWorkerWithInvocationIdAsync(invocationId);
571+
var result = await dispatcher.RestartWorkerWithInvocationIdAsync(invocationId, new FunctionTimeoutException());
574572

575-
// Assert
576573
Assert.True(result);
577574
mockWebHostChannelManager.Verify(m => m.ShutdownChannelIfExistsAsync(
578575
It.IsAny<string>(),
579576
It.Is<string>(id => id == "testChannelId"),
580-
It.Is<Exception>(ex => ex is TimeoutException && ex.Message == $"Executing invocation `{invocationId}` timed out")),
577+
It.Is<Exception>(ex => ex is FunctionTimeoutException)),
581578
Times.Once);
582579
}
583580

@@ -591,24 +588,20 @@ public async Task FunctionDispatcher_RestartOfTimedOutChannels_JobHostFailsCurre
591588

592589
SetUpMocksForTimeoutTests(mockWebHostChannelManager, mockJobHostChannelManager, mockChannel, invocationId, false);
593590

594-
// Setup for initialization of a new channel
595591
var workerConfig = new RpcWorkerConfig
596592
{
597593
Description = new RpcWorkerDescription { Language = "test" },
598594
CountOptions = new WorkerProcessCountOptions { ProcessCount = 1 }
599595
};
600596

601-
// Create the dispatcher with our mocks
602597
var dispatcher = GetTestFunctionDispatcher(mockwebHostLanguageWorkerChannelManager: mockWebHostChannelManager, mockJobHostLanguageWorkerChannelManager: mockJobHostChannelManager);
603598

604-
// Act
605-
var result = await dispatcher.RestartWorkerWithInvocationIdAsync(invocationId);
599+
var result = await dispatcher.RestartWorkerWithInvocationIdAsync(invocationId, new FunctionTimeoutException());
606600

607-
// Assert
608601
Assert.True(result);
609602
mockJobHostChannelManager.Verify(m => m.ShutdownChannelIfExistsAsync(
610603
It.Is<string>(id => id == "testChannelId"),
611-
It.Is<Exception>(ex => ex is TimeoutException && ex.Message == $"Executing invocation `{invocationId}` timed out")),
604+
It.Is<Exception>(ex => ex is FunctionTimeoutException)),
612605
Times.Once);
613606
}
614607

@@ -956,13 +949,13 @@ private void SetUpMocksForTimeoutTests(Mock<IWebHostRpcWorkerChannelManager> moc
956949
mockWebHostChannelManager.Setup(m => m.ShutdownChannelIfExistsAsync(
957950
It.IsAny<string>(),
958951
It.Is<string>(id => id == "testChannelId"),
959-
It.Is<Exception>(ex => ex is TimeoutException && ex.Message == $"Executing invocation `{invocationId}` timed out")))
952+
It.Is<Exception>(ex => ex is FunctionTimeoutException)))
960953
.ReturnsAsync(webHostShutdownSucceeds);
961954

962955
// Set up JobHost ShutdownChannelIfExistsAsync to be called with the right exception type
963956
mockJobHostChannelManager.Setup(m => m.ShutdownChannelIfExistsAsync(
964957
It.Is<string>(id => id == "testChannelId"),
965-
It.Is<Exception>(ex => ex is TimeoutException && ex.Message == $"Executing invocation `{invocationId}` timed out")))
958+
It.Is<Exception>(ex => ex is FunctionTimeoutException)))
966959
.ReturnsAsync(!webHostShutdownSucceeds);
967960
}
968961
}

0 commit comments

Comments
 (0)