azure-functions-dotnet-worker: Using comments in host.json fails silently for isolated worker using the ASP.NET integration
When using comments in host.json the file is not loaded and no error is reported. All settings set in host.json are ignored and the default settings are applied. There is no log output related to this issue.
Repro steps
- Add some easy to test setting in host.json (e.g.
extensions.http.routePrefix - Add a comment somewhere in host.json
- Start the function and observe that the host.json was not loaded. No error is generated.
Expected behavior
The application fails to start and reports an error.
Actual behavior
The application starts and no error is shown. The settings are not loaded.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 7
- Comments: 20 (1 by maintainers)
Commits related to this issue
- host.json: Ignore comments and trailing commas see https://github.com/Azure/azure-functions-host/issues/9583 — committed to fowl2/azure-functions-dotnet-worker by fowl2 2 years ago
I’m disappointed that there is no concrete progress on this issue. I experienced this when upgraded a Functions project from .net6 to .net8 and the VS 2022 Upgrade Assistant replaced “ConfigureFunctionsWorkerDefaults” with “ConfigureFunctionsWebApplication”. There are no errors when starting the app but it doesn’t respond to http requests. The line " Executing ‘Functions.Common_Info’ (Reason=‘This function was programmatically called via the host APIs.’, Id=ea32ee64-a5bd-4bf5-9303-8e7634166a0d)" shows, but nothings happens, see image.
The correct behavior in my opinion is to parse the json even when there are comments, that will make it backward compatible. If that is not feasible an exception should be raised. Please fix this so the transition from .net6 to .net8 is smooth and doesn’t waste hours for others that will run into this.
The behavior you are describing is expected in Azure Functions. The
host.jsonfile in Azure Functions is used to configure various settings for the host environment and your functions, such as function timeout, CORS settings, and extensions configuration. However, comments are not supported in thehost.jsonfile, and they do not cause the application to fail or produce errors.Here’s why comments in
host.jsonbehave this way:JSON Specification: JSON (JavaScript Object Notation) is a data interchange format, and according to the JSON specification, it does not support comments. Comments are not part of the JSON standard, so JSON parsers, including the one used by Azure Functions, will ignore comments.
Azure Functions Host: The Azure Functions runtime is designed to be robust and fault-tolerant. It is configured to ignore unsupported constructs in configuration files like
host.jsonrather than failing the application startup.To address this issue, consider using other means to document your configuration settings, such as creating a separate document or readme file that describes the settings and their purposes. You can also use descriptive key names to make the purpose of each configuration setting clear within
host.json.Here’s an example of how you might structure
host.jsonwith descriptive key names:In this example, the key names (
routePrefix,setting1,setting2) are chosen to be descriptive, making it easier for someone reading the configuration to understand the purpose of each setting without the need for comments.Closed by https://github.com/Azure/azure-functions-dotnet-worker/pull/2851
This is not true. They prevent the application from loading the host.json file which can be mandatory depending on the use case. If for example the routePrefix is not read all HTTP endpoints are configured with the wrong route.
Which is not the case either since using JSON comments in host.json causes the application to not properly load the configuration. This is what this issue is all about. I’ve spend six hours debugging this issue just to find out that some commented out setting causes the whole application to not even start properly.
This is not true either. If the host.json includes some invalid characters rendering the JSON format invalid the function host won’t start.
Excuse me, please what?! This is a bug report and not some SO question asking for advice on how to document my settings. My issue is that commenting out certain keys in the host.json creates an unexpected result and provides no warning or notice whatsoever. This cannot be intended if a structurally invalid host.json is preventing the host from starting.
I would like to request a member or contributor of this repository to address this issue rather than some random person telling me how to document my stuff when I’m reporting a bug.
IMO the most robust solution (i.e. least likely to unnecessarily break the application) is to ignore comments in host.json during parsing. From what I can tell this is also the original behavior of the functions host - prior to moving to the isolated worker. So, disallowing comments is a breaking change.
FYI, ignoring comments seems to be a simple matter of configuring System.Text.Json: https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsoncommenthandling?view=netcore-3.1
Having also fallen fowl of this I want to voice my agreement with @klemmchr. The JSON parser should be able tolerate comments properly, without silently failing.
Whilst comments may not be part of the JSON specification they are commonly used elsewhere in the stack, such as local.settings.json. It should be consistent. It needs to be fixed.
I also lost a good 5+ hours to this. You would think at the very least the official upgrade tooling would check for this sort of thing. I’ve been very disappointed with the upgrade process given how it’s been touted as very low effort officially.
Agree with @ericsson007, after upgrading to .net 8 and isolated, I was not sure why suddenly I am not able to debug locally. I added additional project to test the same but in the end found that I was not able to debug because there was a comment in my
host.jsonfile. This should be fixed!Edited Using the ASP.NET Core integration makes incoming HTTP requests fail, if there are comments in host.json.
The failures start if I use
ConfigureFunctionsWebApplication.With
ConfigureFunctionsWorkerDefaultsthen there are no failures (but possibly the host.json is being silently ignored, I haven’t verified that)MS, before fixing this, please investigate how this failure is seen by the user. The exception is logged, but no response comes back. It just sits there until eventual App Service timeout (
<html><head><title>500 - The request timed out....)Correct. Comments were always previously allowed in
host.json. I suppose originally a side effect of Newtonsoft.Json, but Microsoft official samples relied (rely?) upon the behaviour.What a waste of time debugging this. At no point in the isolated model upgrade documentation does it mention comments are no longer supported in the host.json file.