You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to open connections using pgbouncer in Transaction pool_mode #616
I'm trying to connect to our postgres server via pgbouncer. If pgbouncer's pool_mode is set to session, this works fine. If pgbouncer's pool_mode is set to transaction, this does not work fine.
Here's the error I get when in transaction mode:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Npgsql.dll!Npgsql.NpgsqlBuffer.Ensure(int count) Line 93 + 0x64 bytes C#
Npgsql.dll!Npgsql.NpgsqlConnector.DoReadSingleMessage(Npgsql.DataRowLoadingMode dataRowLoadingMode, bool returnNullForAsyncMessage) Line 848 C#
Npgsql.dll!Npgsql.NpgsqlConnector.ReadSingleMessage(Npgsql.DataRowLoadingMode dataRowLoadingMode, bool returnNullForAsyncMessage) Line 822 + 0x14 bytes C#
Npgsql.dll!Npgsql.NpgsqlCommand.Execute(System.Data.CommandBehavior behavior) Line 719 + 0x24 bytes C#
Npgsql.dll!Npgsql.NpgsqlCommand.ExecuteDbDataReaderInternal(System.Data.CommandBehavior behavior) Line 948 + 0x12 bytes C#
Npgsql.dll!Npgsql.NpgsqlCommand.ExecuteDbDataReader(System.Data.CommandBehavior behavior) Line 933 + 0xe bytes C#
Npgsql.dll!Npgsql.NpgsqlCommand.ExecuteReader(System.Data.CommandBehavior behavior) Line 902 + 0xe bytes C#
Npgsql.dll!Npgsql.TypeHandlerRegistry.LoadBackendTypes(Npgsql.NpgsqlConnector connector) Line 103 + 0x16 bytes C#
Npgsql.dll!Npgsql.TypeHandlerRegistry.Setup(Npgsql.NpgsqlConnector connector) Line 57 + 0x3c bytes C#
Npgsql.dll!Npgsql.NpgsqlConnector.Open() Line 409 C#
Npgsql.dll!Npgsql.NpgsqlConnectorPool.GetPooledConnector(Npgsql.NpgsqlConnection Connection) Line 304 + 0x10 bytes C#
Npgsql.dll!Npgsql.NpgsqlConnectorPool.RequestConnector(Npgsql.NpgsqlConnection connection) Line 183 + 0x15 bytes C#
Npgsql.dll!Npgsql.NpgsqlConnection.Open() Line 195 + 0x3f bytes C#
Our other server running Npgsql 2.2.5 runs in transaction mode with no issues.
If there's any more information or if you want me to try something out, please let me know. Thanks.
@oldsaltycrab, thanks for this report bug (and for all the other high-quality ones you've been sending).
The problem was due to Npgsql trying to SET the PostgreSQL statement_timeout parameter - this isn't supported in transaction mode. There appears to be a pgbouncer issue which makes it lose sync when this happens rather than emit a proper error (opened pgbouncer/pgbouncer#52 for this). The problem disappears when you set CommandTimeout=0 in the connection string (the default is 30).
I did push a change that improves the situation a little bit: the initial setting of the statement_timeout is now down in the startup packet as part of the connection process. Apart from being more correct, it makes pgbouncer issue a clear error that statement_timeout isn't supported, which is much better than the weird behavior you saw.
@roji thanks for looking into this so quickly. I grabbed c5f2caa from your new branch (release-3.0.0) and I now see a clearer error regarding the statement_timeout parameter.
One thing that seems to have changed is that I now get this error when pgbouncer pool_mode is set to session as well as when it's set to transaction. Is that expected from your change?
Thinking about it now, yes, it is expected - my change makes Npgsql send the statement_timeout parameter in the startup packet, and this doesn't seem to be supported in pgbouncer even in session mode (this is clearly stated in their docs).
I'm not sure why pgbouncer is so restrictive with its startup parameters, at least in session mode. I know this new situation is somewhat annoying, but it does seem to be the "proper" PostgreSQL way to do things even if pgbouncer doesn't work with it. You can still specify timeouts individually on each command and it will work (in session mode), but you have to disable the startup parameter by setting CommandTimeout=0...
Let me know you see things another way. And just in case you're not aware, you can grab proper CI nugets from the Npgsql unstable feed rather than getting sources and building yourself...
Activity
Set statement_timeout in startup packet
roji commentedon May 24, 2015
@oldsaltycrab, thanks for this report bug (and for all the other high-quality ones you've been sending).
The problem was due to Npgsql trying to SET the PostgreSQL
statement_timeoutparameter - this isn't supported in transaction mode. There appears to be a pgbouncer issue which makes it lose sync when this happens rather than emit a proper error (opened pgbouncer/pgbouncer#52 for this). The problem disappears when you setCommandTimeout=0in the connection string (the default is 30).I did push a change that improves the situation a little bit: the initial setting of the
statement_timeoutis now down in the startup packet as part of the connection process. Apart from being more correct, it makes pgbouncer issue a clear error thatstatement_timeoutisn't supported, which is much better than the weird behavior you saw.Let me know if everything works as expected now.
oldsaltycrab commentedon May 25, 2015
@roji thanks for looking into this so quickly. I grabbed c5f2caa from your new branch (release-3.0.0) and I now see a clearer error regarding the
statement_timeoutparameter.One thing that seems to have changed is that I now get this error when pgbouncer
pool_modeis set tosessionas well as when it's set totransaction. Is that expected from your change?roji commentedon May 25, 2015
Thinking about it now, yes, it is expected - my change makes Npgsql send the
statement_timeoutparameter in the startup packet, and this doesn't seem to be supported in pgbouncer even insessionmode (this is clearly stated in their docs).I'm not sure why pgbouncer is so restrictive with its startup parameters, at least in
sessionmode. I know this new situation is somewhat annoying, but it does seem to be the "proper" PostgreSQL way to do things even if pgbouncer doesn't work with it. You can still specify timeouts individually on each command and it will work (insessionmode), but you have to disable the startup parameter by settingCommandTimeout=0...Let me know you see things another way. And just in case you're not aware, you can grab proper CI nugets from the Npgsql unstable feed rather than getting sources and building yourself...
oldsaltycrab commentedon May 26, 2015
Ya I think you've done the correct thing.
And yes, hooking up to that nuget feed would probably make more sense..., though the workflow I have now works nicely into our team's Perforce setup.
roji commentedon May 26, 2015
Whatever works for you :)
And keep sending those bug reports :)
roji commentedon Aug 19, 2015
Note: the pgbouncer error where it was losing sync (pgbouncer/pgbouncer#52) has been resolved in their master branch.