-
-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Postgres db command execution fails with npgsql and multihost (primary/replica) connection #1110
Comments
Thanks for the quick fix. I think there might still be an issue with the initial schema creation though. I'm still seeing this exception when I start up my project, but I can't tell if this is Wolverine, Marten, or both.
It looks like both projects depend on Weasel for applying db changes, so perhaps there's something missing there? I was looking thru Weasel and thought maybe this file needs to specify the Target Session Attribute: https://github.com/JasperFx/weasel/blob/master/src/Weasel.Postgresql/Connections/DefaultNpgsqlDataSourceFactory.cs If you agree, I'm happy to submit a PR. |
Damn, I thought we only had a single entry-point for npgsql DS usage. I'll properly test this end to end over the weekend. |
Could you try using |
@rolyv I think we might need a little more information about how you're bootstrapping. Wolverine would be taking the NpgsqlDataSource from Marten's usage if you were using |
I am using I was able to confirm that the NpgsqlDataSourceBuilder returns an instance of NpgsqlMultiHostDataSource if the connection string has multiple hosts: https://github.com/npgsql/npgsql/blob/main/src/Npgsql/NpgsqlSlimDataSourceBuilder.cs#L645 Output from debug console when trying to get NpgsqlDataSource:
|
Would you be able to provide a reproduction? I've configured a wolverine + marten environment with a multi-host configuration and I'm unable to get it to error out. You might be using a feature I haven't accounted for. |
Sorry for the delay. It took me a while to come up with a consistent repro. I created a simple app that uses a lot of the same components I'm using in my real app. I'm guessing there is some randomness in how the host is picked per command. When I had the primary first in the connection string, I wasn't encountering the exception. But when I switched the connection string to have the read replica first, it started happening consistently. But it's not consistent on which command is the one that fails. Sometimes it would be a drop command that would fail. Sometimes it's the create function. I created this repo with the app I used to repro the issue. Hope this helps: https://github.com/rolyv/marten-repro |
Describe the bug
We use multi host Postgres connection string that includes a primary and a read replica. We also have Marten ReadSessionPreference set to PreferStandby. Wolverine appears to have issues with this setup and we're seeing exceptions in the logs like this:
To Reproduce
Steps to reproduce the behavior:
Host=primary-ip,read-replica-ip;Username=...;Password=...;Database=...;Load Balance Hosts=true
Expected behavior
Wolverine should be able to execute commands against primary
Additional context
Using Marten 7.29.0
Wolverine 3.1.0
Npgsql 8.0.4
I'm registering NpgsqlDataSource via the Aspire.Npgsql nuget package 8.2.0 extension method
The text was updated successfully, but these errors were encountered: