Skip to content

Transaction scoped DistributedLock is released prematurely #278

@adzhiljano

Description

@adzhiljano

Hey,

Thank you for this great library!

When using a SqlDistributedLock from DistributedLock.SqlServer, scoped to a transaction, it seems that the lock is released before the transaction is commited/rollbacked (sp_releaseapplock executed explicitly before transaction commit)

Wasn't expecting that and thought that this is by design, but then I looked through the code and found the following:

var canSkipExplicitRelease =
this._transactionScoped && (!this.Connection.IsExernallyOwned || !this.Connection.CanExecuteQueries);

If we're in the transaction scoped scenario and the transaction hasn't been commited (connection is externally owned and still open) we'll have
true && (!true || !true) -> true && (false || false) -> true && false -> false

I'm not entirely sure of the meaning behind those properties, but shouldn't it match the comment above this piece of code and be like:

var canSkipExplicitRelease =
                        this._transactionScoped || (!this.Connection.IsExernallyOwned || !this.Connection.CanExecuteQueries);

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions