madelson / DistributedLock

A .NET library for distributed synchronization
MIT License
1.86k stars 192 forks source link

chore: upgrade postgres dependency #209

Closed Meir017 closed 3 months ago

Meir017 commented 4 months ago

When building locally getting the warning -

warning NU1903: Package 'Npgsql' 8.0.2 has a known high severity vulnerability, https://github.com/advisories/GHSA-x9vc-6hfv-hg8c

madelson commented 4 months ago

Thanks for the contribution @Meir017 ! The change looks fine on the surface, but when I run the postgres tests I get 2 of them failing transiently with some consistency. This is the error:

Expected: No Exception to be thrown
  But was:  <System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Npgsql.NpgsqlCommand'.
   at Npgsql.ThrowHelper.ThrowObjectDisposedException(String objectName)
   at Npgsql.NpgsqlCommand.CheckAndGetConnection()
   at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteScalar(Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteScalar()
   at Medallion.Threading.Internal.Data.DatabaseCommand.<>c.<ExecuteScalarAsync>b__11_1(IDbCommand c) in ...\DistributedLock\src\DistributedLock.Core\Internal\Data\DatabaseCommand.cs:line 67
   at Medallion.Threading.Internal.Data.DatabaseCommand.ExecuteAsync[TResult](Func`3 executeAsync, Func`2 executeSync, CancellationToken cancellationToken, Boolean disallowAsyncCancellation, Boolean isConnectionMonitoringQuery) in ...\DistributedLock\src\DistributedLock.Core\Internal\Data\DatabaseCommand.cs:line 144
   at Medallion.Threading.Postgres.PostgresAdvisoryLock.ReleaseAsync(DatabaseConnection connection, PostgresAdvisoryLockKey key, Boolean isTry) in ...\DistributedLock\src\DistributedLock.Postgres\PostgresAdvisoryLock.cs:line 214
   at Medallion.Threading.Internal.Data.MultiplexedConnectionLock.ReleaseAsync[TLockCookie](IDbSynchronizationStrategy`1 strategy, String name, TLockCookie lockCookie) in ...\DistributedLock\src\DistributedLock.Core\Internal\Data\MultiplexedConnectionLock.cs:line 154
   at Medallion.Threading.Internal.Data.MultiplexedConnectionLock.ReleaseAsync[TLockCookie](IDbSynchronizationStrategy`1 strategy, String name, TLockCookie lockCookie) in ...\DistributedLock\src\DistributedLock.Core\Internal\Data\MultiplexedConnectionLock.cs:line 169
   at Medallion.Threading.Internal.SyncViaAsync.<>c__3`1.<<Run>b__3_0>d.MoveNext() in ...\DistributedLock\src\DistributedLock.Core\Internal\SyncViaAsync.cs:line 31
--- End of stack trace from previous location ---
   at Medallion.Threading.Internal.SyncViaAsync.Run[TState,TResult](Func`2 action, TState state) in ...\DistributedLock\src\DistributedLock.Core\Internal\SyncViaAsync.cs:line 61
   at Medallion.Threading.Internal.SyncViaAsync.Run[TState](Func`2 action, TState state) in ...\DistributedLock\src\DistributedLock.Core\Internal\SyncViaAsync.cs:line 28
   at Medallion.Threading.Internal.SyncViaAsync.DisposeSyncViaAsync[TDisposable](TDisposable disposable) in ...\DistributedLock\src\DistributedLock.Core\Internal\SyncViaAsync.cs:line 100
   at Medallion.Threading.Internal.Data.MultiplexedConnectionLock.ManagedFinalizationDistributedLockHandle.Dispose() in ...\DistributedLock\src\DistributedLock.Core\Internal\Data\MultiplexedConnectionLock.cs:line 282
   at Medallion.Threading.Postgres.PostgresDistributedLockHandle.Dispose() in ...\DistributedLock\src\DistributedLock.Postgres\PostgresDistributedLockHandle.cs:line 25
   at Medallion.Threading.Tests.Data.ConnectionStringStrategyTestCases`3.<TestKeepaliveDoesNotCreateRaceCondition>b__5_0() in ...\DistributedLock\src\DistributedLock.Tests\AbstractTestCases\Data\ConnectionStringStrategyTestCases.cs:line 91
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
--- End of stack trace from previous location ---
   at NUnit.Framework.Internal.ExceptionHelper.Rethrow(Exception exception)
   at NUnit.Framework.Internal.Reflect.DynamicInvokeWithTransparentExceptions(Delegate delegate)
   at NUnit.Framework.Internal.ExceptionHelper.RecordException(Delegate parameterlessDelegate, String parameterName)>

  Stack Trace: 
ConnectionStringStrategyTestCases`3.TestKeepaliveDoesNotCreateRaceCondition() line 83
1)    at Medallion.Threading.Tests.Data.ConnectionStringStrategyTestCases`3.TestKeepaliveDoesNotCreateRaceCondition() in ...\DistributedLock\src\DistributedLock.Tests\AbstractTestCases\Data\ConnectionStringStrategyTestCases.cs:line 83

It seems like somehow the connection is getting disposed out from underneath the lock?

Meir017 commented 4 months ago

@madelson does the AppVeyor run the postgres tests?

madelson commented 4 months ago

@madelson does the AppVeyor run the postgres tests?

@Meir017 it does not, unfortunately.

madelson commented 3 months ago

Closing since this was incorporated into #214. Thanks for bringing this to my attention @Meir017 !