Skip to content

Commit 172f833

Browse files
authored
Do not throw when dotnet-isolated app deployed without payload (#8589)
* Skipping the code to throw exception for dotnet isolated app without payload * Added tests * Updated release notes * Fixed typo in comments * Update release_notes.md
1 parent 29fcb5a commit 172f833

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
**Release sprint:** Sprint 125
77
[ [bugs](https://github.com/Azure/azure-functions-host/issues?q=is%3Aissue+milestone%3A%22Functions+Sprint+125%22+label%3Abug+is%3Aclosed) | [features](https://github.com/Azure/azure-functions-host/issues?q=is%3Aissue+milestone%3A%22Functions+Sprint+125%22+label%3Afeature+is%3Aclosed) ]
88
- Fix the bug where debugging of dotnet isolated function apps hangs in visual studio (#8596)
9+
- Host does not throw anymore for dotnet-isolated app without deployed payload (#8311)

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,17 @@ public async Task InitializeAsync(IEnumerable<FunctionMetadata> functions, Cance
277277

278278
var workerConfig = _workerConfigs.Where(c => c.Description.Language.Equals(_workerRuntime, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
279279

280+
// For other OOP workers, workerconfigs are present inside "workers" folder of host bin directory and is used to populate "_workerConfigs".
281+
// For dotnet-isolated _workerConfigs is populated by reading workerconfig.json from the deployed payload(customer function app code).
282+
// So if workerConfig is null and worker runtime is dotnet-isolated, that means isolated function code was not deployed yet.
283+
var isDotNetIsolatedAppWithoutPayload = string.Equals(_workerRuntime, RpcWorkerConstants.DotNetIsolatedLanguageWorkerName, StringComparison.InvariantCultureIgnoreCase)
284+
&& workerConfig == null;
285+
280286
// We are skipping this check for multi-language environments because they use multiple workers and thus doesn't honor 'FUNCTIONS_WORKER_RUNTIME'
281-
if ((workerConfig == null && (functions == null || functions.Count() == 0)) && !_environment.IsMultiLanguageRuntimeEnvironment())
287+
// Also, skip if dotnet-isolated app without payload as it is a valid case to exist.
288+
if ((workerConfig == null && (functions == null || functions.Count() == 0))
289+
&& !_environment.IsMultiLanguageRuntimeEnvironment()
290+
&& !isDotNetIsolatedAppWithoutPayload)
282291
{
283292
// Only throw if workerConfig is null AND some functions have been found.
284293
// With .NET out-of-proc, worker config comes from functions.

src/WebJobs.Script/Workers/Rpc/RpcWorkerConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static class RpcWorkerConstants
1818
// This will override the default directories.
1919
public const string FunctionsUnixSharedMemoryDirectories = "FUNCTIONS_UNIX_SHARED_MEMORY_DIRECTORIES";
2020
public const string DotNetLanguageWorkerName = "dotnet";
21+
public const string DotNetIsolatedLanguageWorkerName = "dotnet-isolated";
2122
public const string NodeLanguageWorkerName = "node";
2223
public const string JavaLanguageWorkerName = "java";
2324
public const string PowerShellLanguageWorkerName = "powershell";

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,27 @@ public async Task FunctionDispatcherState_Default_DotNetFunctions()
330330
Assert.Equal(FunctionInvocationDispatcherState.Default, functionDispatcher.State);
331331
}
332332

333+
[Fact]
334+
public async Task InitializeAsync_Throws_When_Worker_Config_not_found()
335+
{
336+
// Our GetTestFunctionDispatcher return a dispatcher with 2 worker configs loaded(java, node)
337+
RpcFunctionInvocationDispatcher functionDispatcher = GetTestFunctionDispatcher(runtime: "python");
338+
339+
Func<Task> task = () => functionDispatcher.InitializeAsync(new List<FunctionMetadata>());
340+
341+
InvalidOperationException exception = await Assert.ThrowsAsync<InvalidOperationException>(task);
342+
Assert.Equal("WorkerConfig for runtime: python not found", exception.Message);
343+
}
344+
345+
[Fact]
346+
public async Task InitializeAsync_DoesNotThrow_ForDotNetIsolatedWithoutDeployedPayload()
347+
{
348+
RpcFunctionInvocationDispatcher functionDispatcher = GetTestFunctionDispatcher(runtime: RpcWorkerConstants.DotNetIsolatedLanguageWorkerName);
349+
350+
// Should not throw for dotnet-isolated runtime.
351+
await functionDispatcher.InitializeAsync(new List<FunctionMetadata>());
352+
}
353+
333354
[Fact]
334355
public async Task FunctionDispatcherState_Default_NoFunctions()
335356
{

0 commit comments

Comments
 (0)