Skip to content

Unable to open connections using pgbouncer in Transaction pool_mode #616

Closed

Description

@oldsaltycrab

Hello, I'm on the develop branch at c53f16d.

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.

Activity

  1. added a commit that references this issue on May 24, 2015
    49a5929
  2. roji commented on May 24, 2015

    @roji
    Member

    @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.

    Let me know if everything works as expected now.

  3. oldsaltycrab commented on May 25, 2015

    @oldsaltycrab
    Author

    @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?

  4. roji commented on May 25, 2015

    @roji
    Member

    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...

  5. oldsaltycrab commented on May 26, 2015

    @oldsaltycrab
    Author

    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.

  6. roji commented on May 26, 2015

    @roji
    Member

    Whatever works for you :)

    And keep sending those bug reports :)

  7. roji commented on Aug 19, 2015

    @roji
    Member

    Note: the pgbouncer error where it was losing sync (pgbouncer/pgbouncer#52) has been resolved in their master branch.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions