GithubHelp home page GithubHelp logo

SqlException Transaction (Process ID 66) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction. about durabletask-mssql HOT 4 OPEN

yehiyam avatar yehiyam commented on June 24, 2024
SqlException Transaction (Process ID 66) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

from durabletask-mssql.

Comments (4)

yehiyam avatar yehiyam commented on June 24, 2024
image

from durabletask-mssql.

yehiyam avatar yehiyam commented on June 24, 2024

Kind ping
@cgillum

from durabletask-mssql.

cgillum avatar cgillum commented on June 24, 2024

We should be automatically retrying deadlocks, so I wonder if those retries are being exhausted. Unfortunately, it's hard to fix these without having a reliable repro that can be used for testing.

Are you comfortable making changes directly to your database? One thing you can try is changing the deadlock priority of the dt.QuerySingleOrchestration stored procedure, adding a SET DEADLOCK_PRIORITY HIGH to the top of the procedure to make it more likely to survive deadlocks.

For example, you'd need to do an ALTER PROCEDURE statement similar to the following:

ALTER PROCEDURE [dt].[QuerySingleOrchestration]
    @InstanceID varchar(100),
    @ExecutionID varchar(50) = NULL,
    @FetchInput bit = 1,
    @FetchOutput bit = 1
AS
BEGIN
    SET DEADLOCK_PRIORITY HIGH

    DECLARE @TaskHub varchar(50) = dt.CurrentTaskHub()

    SELECT TOP 1
        I.[InstanceID],
        I.[ExecutionID],
        I.[Name],
        I.[Version],
        I.[CreatedTime],
        I.[LastUpdatedTime],
        I.[CompletedTime],
        I.[RuntimeStatus],
        I.[ParentInstanceID],
        (SELECT TOP 1 [Text] FROM Payloads P WHERE
            P.[TaskHub] = @TaskHub AND
            P.[InstanceID] = I.[InstanceID] AND
            P.[PayloadID] = I.[CustomStatusPayloadID]) AS [CustomStatusText],
        CASE WHEN @FetchInput = 1 THEN (SELECT TOP 1 [Text] FROM Payloads P WHERE
            P.[TaskHub] = @TaskHub AND
            P.[InstanceID] = I.[InstanceID] AND
            P.[PayloadID] = I.[InputPayloadID]) ELSE NULL END AS [InputText],
        CASE WHEN @FetchOutput = 1 THEN (SELECT TOP 1 [Text] FROM Payloads P WHERE
            P.[TaskHub] = @TaskHub AND
            P.[InstanceID] = I.[InstanceID] AND
            P.[PayloadID] = I.[OutputPayloadID]) ELSE NULL END AS [OutputText],
        I.[TraceContext]
    FROM Instances I
    WHERE
        I.[TaskHub] = @TaskHub AND
        I.[InstanceID] = @InstanceID AND
        (@ExecutionID IS NULL OR @ExecutionID = I.ExecutionID)
END

If you're comfortable doing so, can you try and see if that helps?

It doesn't fix the deadlock, but it makes it less likely to impact the ReadEntityStateAsync. Instead, the other deadlock participant will get rolled back. Assuming the other deadlock participant is less important or is a background task that can be automatically retried, this could improve the overall availability of your app. However, it could also just move the problem elsewhere.

If you're able to find a way to reproduce this consistently, I could use that reproducer to find a more reliable/permanent fix.

from durabletask-mssql.

yehiyam avatar yehiyam commented on June 24, 2024

Hi @cgillum
I manually applied your change to the stored procedure and it seems to help. After the fix, I wasn't able to reproduce the error.
Is there a way to apply it programmatically when the process starts?
Currently, we are letting the SDK create the DB with the flag task.StorageProvider["createDatabaseIfNotExists"] = true;

from durabletask-mssql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.