MiloszKrajewski / Hangfire.Storage.MySql

Hangfire storage adapter for MySql / fork of not maintained Hangfire.MySqlStorage
MIT License
42 stars 10 forks source link

MySqlConnector.MySqlException: "get_lock(:vtg1, :vtg2) allowed only with dual" #7

Closed failing closed 2 years ago

failing commented 2 years ago

I am trying to set up your MySql storage extension for HangFire and getting into some trouble. I am using .NET 6 with a MySql version of 8.0.23

This is on a fresh database from PlantScale

Seems to be when it tries to acquire the locks when first starting up. Here is the stacktrace I am getting

at MySqlConnector.MySqlDataReader.ActivateResultSet() in /_/src/MySqlConnector/MySqlDataReader.cs:line 129
   at MySqlConnector.MySqlDataReader.<CreateAsync>d__97.MoveNext() in /_/src/MySqlConnector/MySqlDataReader.cs:line 422
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.Core.CommandExecutor.<ExecuteReaderAsync>d__0.MoveNext() in /_/src/MySqlConnector/Core/CommandExecutor.cs:line 61
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
   at MySqlConnector.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) in /_/src/MySqlConnector/MySqlCommand.cs:line 255
   at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   at Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(IDbCommand cmd, Boolean wasClosed, CommandBehavior behavior) in C:\projects\dapper\Dapper\SqlMapper.cs:line 1051
   at Dapper.SqlMapper.QueryRowImpl[T](IDbConnection cnn, Row row, CommandDefinition& command, Type effectiveType) in C:\projects\dapper\Dapper\SqlMapper.cs:line 1177
   at Dapper.SqlMapper.QueryFirst[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable1 commandTimeout, Nullable1 commandType) in C:\projects\dapper\Dapper\SqlMapper.cs:line 741
   at Hangfire.Storage.MySql.Locking.ResourceLock.TryAcquireLock(TimeSpan timeout)
   at Hangfire.Storage.MySql.Locking.ResourceLock.Acquire(CancellationToken token, DateTime expiration)
   at Hangfire.Storage.MySql.Locking.ResourceLock.AcquireMany(IDbConnection connection, IDbTransaction transaction, String tablePrefix, TimeSpan timeout, CancellationToken token, String[] resourceNames)
   at Hangfire.Storage.MySql.MySqlObjectsInstaller.Upgrade(MySqlConnection connection, String tablesPrefix)
   at Hangfire.Storage.MySql.MySqlStorage..ctor(String connectionString, MySqlStorageOptions storageOptions)

And here are my configuration values:

var options = new MySqlStorageOptions  
    {
        TransactionIsolationLevel = IsolationLevel.ReadCommitted,
        QueuePollInterval = TimeSpan.FromSeconds(15),
        JobExpirationCheckInterval = TimeSpan.FromHours(1),
        CountersAggregateInterval = TimeSpan.FromMinutes(5),
        PrepareSchemaIfNecessary = true,
        DashboardJobListLimit = 50000,
        TransactionTimeout = TimeSpan.FromMinutes(1),
        TablesPrefix = "Hangfire"
    };
var storage = new MySqlStorage("Server=host;user=user;password=password;SslMode=VerifyFull;", options);

builder.Services.AddHangfire(configuration => configuration
    .UseSimpleAssemblyNameTypeSerializer()
    .UseStorage(storage)
    .UseRecommendedSerializerSettings());

// Add the processing server as IHostedService
builder.Services.AddHangfireServer();

Mostly all the defaults - Any input would be great

MiloszKrajewski commented 2 years ago

I have a guess: You are not doing anything wrong, but it seems new version of MySQL is complaining about SQL. Feels like MySQL just got stricter. Requires select get_lock(...) from dual instead of just select get_lock(...). I'll take a look.