镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Error acquiring lock on PostgreSQL when using Npgsql 8.0 #174

Closed

Description

@wazzamatazz

I'm using DistributedLock.Postgres in a project that is using EF Core 7 and Npgsql 7. If I update the project to use EF Core 8 and Npgsql 8 RC2 I am no longer able to acquire a lock. Instead, I see an error and stack trace like the following:

System.InvalidOperationException: Unexpected value '' from acquire command
   at Medallion.Threading.Postgres.PostgresAdvisoryLock.TryAcquireAsync(DatabaseConnection connection, String resourceName, TimeoutValue timeout, CancellationToken cancellationToken) in /_/DistributedLock.Postgres/PostgresAdvisoryLock.cs:line 112
   at Medallion.Threading.Internal.Data.MultiplexedConnectionLock.TryAcquireAsync[TLockCookie](String name, TimeoutValue timeout, IDbSynchronizationStrategy`1 strategy, TimeoutValue keepaliveCadence, CancellationToken cancellationToken, Boolean opportunistic) in /_/DistributedLock.Core/Internal/Data/MultiplexedConnectionLock.cs:line 74
   at Medallion.Threading.Internal.Data.MultiplexedConnectionLock.TryAcquireAsync[TLockCookie](String name, TimeoutValue timeout, IDbSynchronizationStrategy`1 strategy, TimeoutValue keepaliveCadence, CancellationToken cancellationToken, Boolean opportunistic) in /_/DistributedLock.Core/Internal/Data/MultiplexedConnectionLock.cs:line 94
   at Medallion.Threading.Internal.Data.MultiplexedConnectionLockPool.TryAcquireAsync[TLockCookie](String connectionString, String name, TimeoutValue timeout, IDbSynchronizationStrategy`1 strategy, TimeoutValue keepaliveCadence, CancellationToken cancellationToken) in /_/DistributedLock.Core/Internal/Data/MultiplexedConnectionLockPool.cs:line 91
   at Medallion.Threading.Internal.Data.MultiplexedConnectionLockPool.TryAcquireAsync[TLockCookie](String connectionString, String name, TimeoutValue timeout, IDbSynchronizationStrategy`1 strategy, TimeoutValue keepaliveCadence, CancellationToken cancellationToken) in /_/DistributedLock.Core/Internal/Data/MultiplexedConnectionLockPool.cs:line 97
   at Medallion.Threading.Internal.DistributedLockHelpers.Wrap[THandle](ValueTask`1 handleTask, Func`2 factory) in /_/DistributedLock.Core/Internal/DistributedLockHelpers.cs:line 41
   at Medallion.Threading.Internal.DistributedLockHelpers.ThrowTimeoutIfNull[T](ValueTask`1 task, String object) in /_/DistributedLock.Core/Internal/DistributedLockHelpers.cs:line 142

I am creating the lock by passing the connection string to the PostgresDistributedLock constructor rather than an IDbConnection instance but I've found that I get the same error regardless of which constructor I use.

Reverting to EF Core 7/Npgsql 7 immediately fixes the issue.

Activity

  1. Kaffeetasse commented on Nov 17, 2023

    @Kaffeetasse
    Contributor

    I think the reason is, the AcquireCommand returns now a null value instead of DBNull.

    In this line:

    acquireCommandResult = await acquireCommand.ExecuteScalarAsync(cancellationToken).ConfigureAwait(false);

  2. valentasm1 commented on Nov 21, 2023

    @valentasm1

    Any workaround?

  3. madelson commented on Nov 21, 2023

    @madelson
    Owner

    @Kaffeetasse appreciate the diagnosis. Seems like this is a breaking change in Npgsql (I wonder if it is intentional).

    fixing this in the package would be very easy; we can simply detect when it gets the “wrong” value and convert to what we expect.

    I’d be happy to look at a PR for this. Otherwise, I can hopefully get to it in a few weeks.

  4. added a commit that references this issue on Nov 22, 2023
    3c0b6dc
  5. valentasm1 commented on Nov 27, 2023

    @valentasm1

    Any time when someone will find time to review and release it?

  6. madelson commented on Nov 27, 2023

    @madelson
    Owner

    @valentasm1 I should be able to do it in the next few days.

  7. added a commit that references this issue on Nov 28, 2023
    59ae38b
  8. added this to the 2.3.4 milestone on Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdependenciesPull requests that update a dependency file

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions