madelson / DistributedLock

A .NET library for distributed synchronization
MIT License
1.82k stars 185 forks source link

Postgres: allow ShouldPrepareCommands to be false to work with npgsql driver Multiplexing #225

Open samcarton opened 1 month ago

samcarton commented 1 month ago

Here the code is hard-coding DatabaseConnection.ShouldPrepareCommands to true: https://github.com/madelson/DistributedLock/blob/ce4a071dc2e87cf4295a9be4d1e20bbfe4a467e9/src/DistributedLock.Postgres/PostgresDatabaseConnection.cs#L36

However we have npgsql's multiplexing enabled on the connection string, which doesn't allow explicit preparation (see related comment in issue). It results in a Explicit preparation not supported with multiplexing NotSupportedException.

madelson commented 1 month ago

Ideally it would just work, meaning that either we always set should prepare to false for Postgres (how important is it with the current driver?) or we default it based on whether the connection is multiplexing.

That said, I’m curious as to whether distributed locking works with a multiplexed Postgres connection. Is it still able to know which session is holding the lock?