Sitelet https://github.com/npgsql/npgsql/issues/5029
Skip to content

Consider allowing to make another attempt to connect to postgresql without ssl on network errors with SslMode.Prefer #5029

Description

@vonzshik

Currently, we only allow to make another attempt to connect to postgresql if we get error 28000 while authenticating:

try
{
await conn.Authenticate(username, timeout, async, cancellationToken);
}
catch (PostgresException e)
when (e.SqlState == PostgresErrorCodes.InvalidAuthorizationSpecification &&
(sslMode == SslMode.Prefer && conn.IsSecure || sslMode == SslMode.Allow && !conn.IsSecure))

While this behavior aligns with pgjdbc, in some cases we might not get an error and instead fail with Exception while reading from stream. This happens due to postgresql bug on windows, where due to the way postgresql closes the connection, we're essentially racing with whether we'll be able to read pg error from the socket or not.

We can think about making it so we always make another attempt without ssl for any sort of error.

Activity

  1. added this to the Backlog milestone on Apr 7, 2023
  2. added theissue type on Jun 14, 2025
  3. trivalik commented on Nov 5, 2025

    @trivalik
    Contributor

    @vonzshik I think this is fixed now by #6287.

  4. vonzshik commented on Nov 5, 2025

    @vonzshik
    ContributorAuthor

    Ha, I forgot that I actually made an issue about this specific problem.

  5. removed this from the Backlog milestone on Nov 5, 2025
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions