Base solution for your next web application
Open Closed

Site stops working after database connection drops because of network issue #12429


User avatar
0
mmukkara created

Hi,

We have an issue in production.. When there was some network outage for a fraction of a second, the database connection dropped for the database server. There is no Connection resiliency which should automatically retries. Because of this, the server stops with error and we had downtime. We had to restart the api server to establish the connection. Can you please check and let us know how to fix this issue.

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

3 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @mmukkara

    The issue you experienced was due to a brief network outage which caused the database connection to drop. Since connection resiliency is not currently enabled in your application, the dropped connection was not automatically retried, resulting in the API server failing with an error. Are these settings active for you? Can you try this?

    You can enable automatic retries on transient failures using the EnableRetryOnFailure() method.

    Example configuration: YourProjectName.EntityFrameworkCore --> YourProjectName.DbContextConfigurer.cs

    options.UseSqlServer(
        connectionString,
        sqlServerOptions =>
        {
            sqlServerOptions.EnableRetryOnFailure(
                maxRetryCount: 5,
                maxRetryDelay: TimeSpan.FromSeconds(10),
                errorNumbersToAdd: null
            );
    });
    

    This ensures that the application automatically retries failed database connections a few times before throwing an exception, which helps mitigate temporary outages.

    Possible Causes of This Issue:

    Long-Lived DbContext Instances

    • If DbContext instances are kept alive for too long, any temporary network interruption can invalidate them.
    • Best practice is to use short-lived DbContext instances

    Implement Health Checks: In your ASP.NET Zero application, we recommend enabling built-in Health Checks to monitor critical dependencies like the database. Related Document

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    mmukkara created

    Health Checks was giving error in the 13.4 version. will test with EnableRetryOnFailure() method as suggested above and get back to you.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @mmukkara

    Thanks for the update! If the issue persists, feel free to share any error details, and I’ll be happy to assist further.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)