Failed to change state to a 'Failed' one due to an exception after 10 retry attempts (v. 1.7.16)

Hi, last version of Hangfire throws erros on exceptions, so automatic retry not working.
Example:
[Queue(“default”)]
[DisplayName(“Test->Test1(txt={0},enqueue={1})”)]
public string Test1(string txt, bool enqueue = true)
{
int x = 0;
int y;
try
{
if (txt == “error”)
y = 1 / x;
return txt;

        }
        catch (Exception ex)
        {
            Logs.Add("Test", KurierzyEnum.X, -1, System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message, ex.ToString(), txt);
            Console.WriteLine(ex.Message);
            throw new Exception(ex.Message);
        }
    }

On dashboard we have:

Failed

Failed to change state to a ‘Failed’ one due to an exception after 10 retry attempts

System.Data.SqlClient.SqlException

Incorrect syntax near ‘throw’.

System.Data.SqlClient.SqlException: Incorrect syntax near ‘throw’.

Please help.!
Test1_method|419x387

Could you show full stack trace of the exception to understand what method caused it?

Here is exception:

System.Data.SqlClient.SqlException

Incorrect syntax near ‘throw’.

System.Data.SqlClient.SqlException: Incorrect syntax near ‘throw’. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean&amp; dataReady) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task&amp; task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean&amp; usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition&amp; command, Action2 paramReader) at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable1 commandTimeout, Nullable1 commandType) at Hangfire.SqlServer.SqlServerConnection.<>c__DisplayClass10_0.<SetJobParameter>b__0(DbConnection connection) at Hangfire.SqlServer.SqlServerStorage.<>c__DisplayClass32_0.<UseConnection>b__0(DbConnection connection) at Hangfire.SqlServer.SqlServerStorage.UseConnection[T](DbConnection dedicatedConnection, Func2 func) at Hangfire.AutomaticRetryAttribute.ScheduleAgainLater(ElectStateContext context, Int32 retryAttempt, FailedState failedState) at Hangfire.States.StateMachine.InvokeOnStateElection(Tuple2 x)

Hi,
last version of Hangfire (1.7.16) throws erros on exceptions, so automatic retry not working.
Example:

    [Queue("default")]
    [DisplayName("Test->Test1(txt={0},enqueue={1})")]
    public string Test1(string txt, bool enqueue = true)
    {
        int x = 0;
        int y;
        try
        {
            if (txt == "error0")
                y = 1 / x;                
            return txt;
            
        }
        catch (Exception ex)
        {                
            Console.WriteLine(ex.Message);
            throw new Exception(ex.Message);
        }
    }

On dashboard we have:

Failed to change state to a ‘Failed’ one due to an exception after 10 retry attempts

System.Data.SqlClient.SqlException

Incorrect syntax near ‘throw’.

System.Data.SqlClient.SqlException: Incorrect syntax near ‘throw’.

Test1_method

  • edit images
  • edit code (formatting)
    I’m using SQL Server, .NET Framework 4.5.2, ASP.NET MVC

Please help

Could you also tell me what version of SQL Server you are using? If you are in rush, downgrade your version to 1.7.14, if not, I will release fix in 1 hour.

Microsoft SQL Server 2008 (SP4) - 10.0.6241.0 (X64) Apr 17 2015 10:56:08 Copyright © 1988-2008 Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.3 (Build 9600: ) (VM)

Ok, I will check 1.7.14.

Same issue on Hangfire 1.7.14

Query is completely different there and does not contain throw statement. Please ensure both Hangfire.Core.dll and Hangfire.SqlServer.dll assemblies have 1.7.14 version. I’m also preparing fix right now.

1 Like

You have right of course.
After downgrade to 1.7.14 everything is ok.
Waiting for official realease 1.7.17 with fixed bug.
Thank you, odinserj :handshake:

Lukasz, I’ve tested the changes against SQL Server 2008 and everything works now. So version 1.7.17 is released now and already available on NuGet. Thank you so much for reporting this issue!