Azure / Azure/azure-functions-host
ArgumentNullException thrown while reading function metadata during host shutdown
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
There's a chance that we throw an exception while reading function metadata while the host is stopping. Before everything is fully initialized, we see a file change, and begin stopping the host. The code below can throw because no functionName can be determined.
https://github.com/Azure/azure-functions-host/blob/bf91f5d6a585428138f273c1787f8c18af0e8eaf/src/WebJobs.Script/Host/ScriptHost.cs#L280
The trace looks like:
```
System.ArgumentNullException : Value cannot be null.
Parameter name: key
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key,TValue& value)
at Microsoft.Azure.WebJobs.Script.ScriptHost.AddFunctionError(Dictionary`2 functionErrors,String functionName,String error,Boolean isFunctionShortName) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script\Host\ScriptHost.cs : 271
at Microsoft.Azure.WebJobs.Script.ScriptHost.ReadFunctionMetadata(String functionDirectory,TraceWriter traceWriter,ILogger logger,Dictionary`2 functionErrors,ScriptSettingsManager settingsManager,IEnumerable`1 functionWhitelist) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script\Host\ScriptHost.cs : 1152
at Microsoft.Azure.WebJobs.Script.ScriptHost.ReadFunctionMetadata(IEnumerable`1 functionDirectories,TraceWriter traceWriter,ILogger logger,Dictionary`2 functionErrors,ScriptSettingsManager settingsManager,IEnumerable`1 functionWhitelist) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script\Host\ScriptHost.cs : 1096
at Microsoft.Azure.WebJobs.Script.ScriptHost.LoadFunctionMetadata() at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script\Host\ScriptHost.cs : 667
at Microsoft.Azure.WebJobs.Script.ScriptHost.Initialize() at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script\Host\ScriptHost.cs : 298
at Microsoft.Azure.WebJobs.Script.ScriptHostManager.RunAndBlock(CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script\Host\ScriptHostManager.cs : 177
```
Note that this is not the cause of the host stopping, and everything continues on as expected with the new host. However, it is noisy and can cause alerts in customers Application Insights accounts due to the exception firing. We've had at least one CRI due to this.
Contributor guide
Research direction
Start in src/WebJobs.Script/Host/ScriptHost.cs around the linked initialization code and trace through ReadFunctionMetadata and AddFunctionError. Reproduce or inspect the host-stopping path where functionName is unavailable, then run the relevant ScriptHost tests if present. Done means shutdown no longer emits the ArgumentNullException or noisy Application Insights exception while the replacement host continues normally.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100