Retry database connections (#5124)

* Retry database connections

* build: fix pr pipeline

* build: fix docker img

* change the build image to SDK

* update codeql

* v3

* fixy
pull/5127/head
Jamie Rees 6 months ago committed by GitHub
parent af8b519b46
commit 38f7ced860
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -37,7 +37,7 @@ jobs:
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
@ -48,7 +48,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v3
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
@ -62,4 +62,4 @@ jobs:
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v3

@ -76,10 +76,10 @@ jobs:
strategy:
matrix:
include:
- os: win10-x64
- os: win-x64
format: zip
compression: zip
- os: win10-x86
- os: win-x86
format: zip
compression: zip
- os: linux-x64

@ -3,11 +3,14 @@ using System.IO;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using MySqlConnector;
using Newtonsoft.Json;
using Ombi.Helpers;
using Ombi.Store.Context;
using Ombi.Store.Context.MySql;
using Ombi.Store.Context.Sqlite;
using Polly;
using Pomelo.EntityFrameworkCore.MySql.Storage.Internal;
using SQLitePCL;
namespace Ombi.Extensions
@ -120,13 +123,40 @@ namespace Ombi.Extensions
public static void ConfigureMySql(DbContextOptionsBuilder options, PerDatabaseConfiguration config)
{
options.UseMySql(config.ConnectionString, ServerVersion.AutoDetect(config.ConnectionString), b =>
if (string.IsNullOrEmpty(config.ConnectionString))
{
throw new ArgumentNullException("ConnectionString for the MySql/Mariadb database is empty");
}
options.UseMySql(config.ConnectionString, GetServerVersion(config.ConnectionString), b =>
{
//b.CharSetBehavior(Pomelo.EntityFrameworkCore.MySql.Infrastructure.CharSetBehavior.NeverAppend); // ##ISSUE, link to migrations?
b.EnableRetryOnFailure();
});
}
private static ServerVersion GetServerVersion(string connectionString)
{
// Workaround Windows bug, that can lead to the following exception:
//
// MySqlConnector.MySqlException (0x80004005): SSL Authentication Error
// ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
// ---> System.ComponentModel.Win32Exception (0x8009030F): The message or signature supplied for verification has been altered
//
// See https://github.com/dotnet/runtime/issues/17005#issuecomment-305848835
//
// Also workaround for the fact, that ServerVersion.AutoDetect() does not use any retrying strategy.
ServerVersion serverVersion = null;
#pragma warning disable EF1001
var retryPolicy = Policy.Handle<Exception>(exception => MySqlTransientExceptionDetector.ShouldRetryOn(exception))
#pragma warning restore EF1001
.WaitAndRetry(3, (count, context) => TimeSpan.FromMilliseconds(count * 250));
serverVersion = retryPolicy.Execute(() => serverVersion = ServerVersion.AutoDetect(connectionString));
return serverVersion;
}
public class DatabaseConfiguration
{
public DatabaseConfiguration()

@ -1,6 +1,5 @@
# build stage
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-jammy-chiseled AS build
LABEL exclaimer-signature-analytics-build=true
FROM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build
ARG VERSION=1.0.0
WORKDIR /source
@ -63,7 +62,7 @@ FROM build AS publish
RUN dotnet publish "Ombi.csproj" -c release --no-restore --no-build -o /app/publish
FROM mcr.microsoft.com/dotnet/aspnet:8.0-jammy-chiseled as base
FROM mcr.microsoft.com/dotnet/aspnet:8.0-jammy as base
WORKDIR /src/Ombi
EXPOSE 5000

Loading…
Cancel
Save