pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Carla Iriberri <ciriberri@salesforce.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: could not accept SSL connection: Success
Date: Thu, 20 Jan 2022 09:32:33 +0900
Message-ID: <YeitoS9IMBAiXzG1@paquier.xyz> (raw)
In-Reply-To: <CA+hUKGLdXHZOss7f2zgF+a9U2CakyYVgPQuOY48wZVSVyUK15Q@mail.gmail.com>
References: <CAPiM8Ai_cuKdF4YVOnCdwHrPWGCUQwiRO_gBU6OAWSUrGhNjeg@mail.gmail.com>
	<YeeWmHJnI2dtzPrp@paquier.xyz>
	<CAPiM8AiLWRsUy7W2EuR3niX+QhiVFCFf4SZv1DJjp5_UDgz4ng@mail.gmail.com>
	<CA+hUKGLdXHZOss7f2zgF+a9U2CakyYVgPQuOY48wZVSVyUK15Q@mail.gmail.com>

On Thu, Jan 20, 2022 at 09:05:35AM +1300, Thomas Munro wrote:
> Good news, I'm glad they nailed that down.  I recall that this
> behaviour was a bit of a moving target in earlier versions:
> 
> https://www.postgresql.org/message-id/CAEepm%3D3cc5wYv%3DX4Nzy7VOUkdHBiJs9bpLzqtqJWxdDUp5DiPQ%40mail...

Ahh..  So you saw the same problem a couple of years back.  This
thread did not catch much attention.

I don't think that it makes much sense to leave this unchecked as the
message is confusing as it stands.  Perhaps we could do something like
the attached by adding a note about OpenSSL 3.0 to revisit this code
once we unplug support for 1.1.1 and avoiding the errno==0 case?  The
frontend has its own ideas of socket failures as it requires thread
support, making things different with the backend, but it seems to me
that we could see cases where SOCK_ERRNO is also 0.  That's mostly
what you suggested on the other thread.

The error handling changes are really cosmetic, so I'd rather leave
the back-branches out of that.  Thoughts?
--
Michael

Attachments:

ssl-eof-errno.patch (text/x-diff, 2.0K) download diff --git a/src/backend/libpq/be-secure-openssl.c b/src/backend/libpq/be-secure-openssl.c index 3d0168a369..12ddc6f82f 100644 --- a/src/backend/libpq/be-secure-openssl.c +++ b/src/backend/libpq/be-secure-openssl.c @@ -493,7 +493,13 @@ aloop: WAIT_EVENT_SSL_OPEN_SERVER); goto aloop; case SSL_ERROR_SYSCALL: - if (r < 0) + /* + * OpenSSL 1.1.1 and older versions return nothing on + * an unexpected EOF, and errno may not be set. Note that + * in OpenSSL 3.0, an unexpected EOF would result in + * SSL_ERROR_SSL with a meaningful error set on the stack. + */ + if (r < 0 && errno != 0) ereport(COMMERROR, (errcode_for_socket_access(), errmsg("could not accept SSL connection: %m"))); diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c index 9f735ba437..b47ea87b43 100644 --- a/src/interfaces/libpq/fe-secure-openssl.c +++ b/src/interfaces/libpq/fe-secure-openssl.c @@ -314,6 +314,12 @@ pgtls_write(PGconn *conn, const void *ptr, size_t len) n = 0; break; case SSL_ERROR_SYSCALL: + /* + * OpenSSL 1.1.1 and older versions return nothing on + * an unexpected EOF, and errno may not be set. Note that + * in OpenSSL 3.0, an unexpected EOF would result in + * SSL_ERROR_SSL with a meaningful error set on the stack. + */ if (n < 0) { result_errno = SOCK_ERRNO; @@ -322,11 +328,14 @@ pgtls_write(PGconn *conn, const void *ptr, size_t len) libpq_gettext("server closed the connection unexpectedly\n" "\tThis probably means the server terminated abnormally\n" "\tbefore or while processing the request.\n")); - else + else if (result_errno != 0) appendPQExpBuffer(&conn->errorMessage, libpq_gettext("SSL SYSCALL error: %s\n"), SOCK_STRERROR(result_errno, sebuf, sizeof(sebuf))); + else + appendPQExpBuffer(&conn->errorMessage, + libpq_gettext("SSL SYSCALL error: internal failure\n")); } else {
signature.asc (application/pgp-signature, 832B) download

view thread (9+ messages)  latest in thread

Message-ID: <YeitoS9IMBAiXzG1@paquier.xyz>
Permalink:  ../YeitoS9IMBAiXzG1@paquier.xyz/
Also on:    postgresql.org/message-id/YeitoS9IMBAiXzG1@paquier.xyz

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: michael@paquier.xyz, thomas.munro@gmail.com, ciriberri@salesforce.com
  Subject: Re: could not accept SSL connection: Success
  In-Reply-To: <YeitoS9IMBAiXzG1@paquier.xyz>
  References: <CAPiM8Ai_cuKdF4YVOnCdwHrPWGCUQwiRO_gBU6OAWSUrGhNjeg@mail.gmail.com> <YeeWmHJnI2dtzPrp@paquier.xyz> <CAPiM8AiLWRsUy7W2EuR3niX+QhiVFCFf4SZv1DJjp5_UDgz4ng@mail.gmail.com> <CA+hUKGLdXHZOss7f2zgF+a9U2CakyYVgPQuOY48wZVSVyUK15Q@mail.gmail.com> <YeitoS9IMBAiXzG1@paquier.xyz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox