Skip to content

Clearing the whole pool when one physical open times out makes overload worse #6765

Open

Description

@milosandric-md

Npgsql 10.0.3, EF Core 10, .NET 10, PostgreSQL on AWS RDS (TLS).

What happens

  1. A burst of requests finds no idle connection. The pool opens a physical connection for each, in parallel, limited only by Max Pool Size.
  2. Under that load, opens get slow (TLS, auth, client CPU). One passes Timeout.
  3. NpgsqlConnector.Open calls Break(e, markHostAsOfflineOnConnecting: true). The exception is a transient NpgsqlException wrapping TimeoutException, so Break marks the database offline and calls DataSource.Clear().
  4. Clear() closes all idle connections, and every busy one is closed when it is returned. The waiting requests open new connections, which are slow again, so more opens time out and the pool is cleared again.

In one incident (Max Pool Size=200) we saw about 1,600 physical opens in a few minutes. About 300 failed, and about 1,200 healthy connections were closed by clears. As far as we can tell, the server was up the whole time.

Questions

  1. Is a full clear on one open timeout intended? Here the timeout means the client is overloaded, not that the server is down, and the clear makes it worse.
  2. Is Cancellation Timeout=-1 the intended way to opt out? It also changes how query cancellation works, so it seems too broad.
  3. Would you consider not clearing on an open timeout (only on a real connection failure), or a setting that limits how many physical opens run at once?

Related: #6427 / #6431 stopped the clear for the GSS/TLS retry case. The final failed open still clears.

Our workaround: Min Pool Size = Max Pool Size, all connections opened at startup a few at a time, and Timeout=30.

Activity

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