-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DatabaseFacade.CanConnect throws instead of returning false #18355
Comments
@rynowak what would be the expected behavior here from the ASP.NET health check perspective? It seems problematic for this method to sometimes throw and sometimes return false - what do other health checks do? |
@rynowak ping |
@rynowak Pinging you now you've been right-side-up for a while. What is the general guidance on health checks and exceptions. Should any error report back as false, or should unexpected errors be surfaced as exceptions? |
I would expect it to return false 😁 Health checks are an abstraction/isolation layer. A health check should return "Unhealthy" if the check fails, that's preferrable to an exception. If the check throws an exception that will be logged differently. Since checks are are abstraction layer, it's also reasonable for a check to handle exceptions from whatever it's checking. Some of them do that because that's the only option. In the case that you want to have the exception convey something meaningful and log that too, it's an option. In general though returning false is preferrable to throwing. |
@rynowak Thanks! |
Hello @roji , we are using EF Core Dbcontext 3.1.0, and the |
@antoinecfmws this was done too late for 3.1.0, so will be released for 5.0.0 (and its previews). This is why this issue is in the 5.0.0 milestone. |
Makes sense now, thank you! Sorry to bother @roji |
On SQL Server, if the database server is down, an SqlException is thrown instead of returning false. It seems like we should catch all exceptions internally and return false instead.
The text was updated successfully, but these errors were encountered: