You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The AddMetadataFromCustomProviders method gets stuck if any of the IFunctionMetadataProvider.GetFunctionMetadataAsync does not return a result.
If you look at the code, we have 2 logging statements, line 217 and 228. When the IFunctionMetadataProvider.GetFunctionMetadataAsync does not return a result, the second log statement is never executed.
The issue can be reproduced by adding the below test to FunctionMetadataManagerTests.cs and run it. The test pass confirms that the log message "1 functions found (Custom)" is not produced.
[Fact]publicvoidFunctionMetadataManager_GetsMetadata_FromFunctionProviders_Deadlock(){varfunctionMetadataCollection=newCollection<FunctionMetadata>();varmockFunctionErrors=newDictionary<string,ImmutableArray<string>>();varmockFunctionMetadataProvider=newMock<IFunctionMetadataProvider>();varmockFunctionProvider=newMock<IFunctionProvider>();varworkerConfigs=TestHelpers.GetTestWorkerConfigs();vartestLoggerProvider=newTestLoggerProvider();varloggerFactory=newLoggerFactory();loggerFactory.AddProvider(testLoggerProvider);mockFunctionMetadataProvider.Setup(m =>m.GetFunctionMetadataAsync(workerConfigs,SystemEnvironment.Instance,false)).Returns(Task.FromResult(newCollection<FunctionMetadata>().ToImmutableArray()));mockFunctionMetadataProvider.Setup(m =>m.FunctionErrors).Returns(newDictionary<string,ICollection<string>>().ToImmutableDictionary(kvp =>kvp.Key, kvp =>kvp.Value.ToImmutableArray()));functionMetadataCollection.Add(GetTestFunctionMetadata("somefile.dll",name:"anotherFunction"));// Mock GetFunctionMetadataAsync to never return a result.vartcs=newTaskCompletionSource<ImmutableArray<FunctionMetadata>>();mockFunctionProvider.Setup(m =>m.GetFunctionMetadataAsync()).Returns(tcs.Task);mockFunctionProvider.Setup(m =>m.FunctionErrors).Returns(mockFunctionErrors.ToImmutableDictionary());FunctionMetadataManagertestFunctionMetadataManager=TestFunctionMetadataManager.GetFunctionMetadataManager(newOptionsWrapper<ScriptJobHostOptions>(_scriptJobHostOptions),mockFunctionMetadataProvider.Object,newList<IFunctionProvider>(){mockFunctionProvider.Object},newOptionsWrapper<HttpWorkerOptions>(_defaultHttpWorkerOptions),loggerFactory,newTestOptionsMonitor<LanguageWorkerOptions>(TestHelpers.GetTestLanguageWorkerOptions()));// Run LoadFunctionMetadata in a separate Task to avoid blocking the test threadvarloadFunctionMetadataTask=Task.Run(()=>testFunctionMetadataManager.LoadFunctionMetadata());// wait 5 seconds for the task to completeAssert.False(loadFunctionMetadataTask.Wait(TimeSpan.FromSeconds(5)));vartraces=testLoggerProvider.GetAllLogMessages();Assert.Equal(1,traces.Count(t =>t.FormattedMessage.Contains("Reading functions metadata (Custom)")));Assert.DoesNotContain(traces, t =>t.FormattedMessage.Contains("1 functions found (Custom)"));}
The text was updated successfully, but these errors were encountered:
kshyju
changed the title
Deadlock in GetFunctionMetadataAsync when IFunvtionProvider.GetFunctionMetadataAsync does not return
Deadlock in GetFunctionMetadataAsync when IFunctionMetadataProvider.GetFunctionMetadataAsync does not return
Jun 11, 2024
The
AddMetadataFromCustomProviders
method gets stuck if any of theIFunctionMetadataProvider.GetFunctionMetadataAsync
does not return a result.If you look at the code, we have 2 logging statements, line 217 and 228. When the
IFunctionMetadataProvider.GetFunctionMetadataAsync
does not return a result, the second log statement is never executed.azure-functions-host/src/WebJobs.Script/Host/FunctionMetadataManager.cs
Lines 217 to 230 in d1067c5
The issue can be reproduced by adding the below test to
FunctionMetadataManagerTests.cs
and run it. The test pass confirms that the log message "1 functions found (Custom)" is not produced.The text was updated successfully, but these errors were encountered: