Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r6Xxx-001JcI-6F for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Nov 2023 15:19:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r6Xxv-00CPpO-PU for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Nov 2023 15:19:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r6Xxv-00CPpE-4t for pgsql-hackers@lists.postgresql.org; Fri, 24 Nov 2023 15:19:35 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r6Xxs-0079ks-1V for pgsql-hackers@postgresql.org; Fri, 24 Nov 2023 15:19:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2023062407; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description; bh=8XO5Z6J27x/aOxR4U1Yb+VUsDkZD/16GqzaJ9Fpu/fo=; b=X1Vb1 OzLoBZ8nQsiktIxkUz18AcIxdq0j15hZfN/ysDq9zLQR/Qq/5sj1zu7oNe7yhBypDHb+tWQroWYJ7 zhRbeQg4BZ8f3yYiievGyauPDClZVhxJBCvl9Q1lvGZJuqutxAuFha6zOHNXs71BitFJMoX5hKZNb u6LJi6ENjAyKxV0XhFjwMAZ0HNFp6kYl3P28ub51lwdnB9nPvnWATrlsaSCqG4OR29um4vd1tAmMu GsK/pd8TQjVDnkOfDz9TqKSoL0Yc4i90U36Ll0nxw3PYqAxRXLARO1FRvwOOMFEk7tmXL/bMzkBH+ Iqik9c+Ao3bx3CW2ZGT+Rl5hXPi8A==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1r6Xxp-001VEA-1Y; Fri, 24 Nov 2023 10:19:29 -0500 Date: Fri, 24 Nov 2023 10:19:29 -0500 From: Bruce Momjian To: Laurenz Albe Cc: Tom Lane , Robert Haas , "pgsql-hackers@postgresql.org" Subject: Re: [HACKERS] psql casts aspersions on server reliability Message-ID: References: <15946.1475068481@sss.pgh.pa.us> <2543635.1700699932@sss.pgh.pa.us> <1e9012b85ffaf04efb13859465804ce9b08ce073.camel@cybertec.at> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="d8M1nhgBiD9I0Y+K" Content-Disposition: inline In-Reply-To: <1e9012b85ffaf04efb13859465804ce9b08ce073.camel@cybertec.at> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --d8M1nhgBiD9I0Y+K Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Nov 24, 2023 at 04:06:22AM +0100, Laurenz Albe wrote: > On Thu, 2023-11-23 at 11:12 -0500, Bruce Momjian wrote: > > On Wed, Nov 22, 2023 at 10:25:14PM -0500, Bruce Momjian wrote: > > > Yes, you are correct. Here is a patch that implements the FATAL test, > > > though I am not sure I have the logic correct or backwards, and I don't > > > know how to test this. Thanks. > > > > I developed the attached patch which seems to work better. In testing > > kill -3 on a backend or calling elog(FATAL) in the server for a > > session, libpq's 'res' is NULL, meaning we don't have any status to > > check for PGRES_FATAL_ERROR. It is very possible that libpq just isn't > > stuctured to have the PGRES_FATAL_ERROR at the point where we issue this > > message, and this is not worth improving. > > > > test=> select pg_sleep(100); > > --> FATAL: FATAL called > > > > server closed the connection unexpectedly > > --> This probably means the server terminated null > > before or while processing the request. > > The connection to the server was lost. Attempting reset: Succeeded. > > I don't thing "terminated null" is a meaningful message. Yes, this is just a debug build so we can see the values of 'res'. Sorry for the confusion. This attached patch has the elog() added so you can reproduce what I saw. I am actually unclear which exits should be labled as "abnormal". -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Only you can decide what is important to you. --d8M1nhgBiD9I0Y+K Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="exit.diff" diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 5d78d6dc06..890fe3bd4a 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -372,6 +372,8 @@ pg_sleep(PG_FUNCTION_ARGS) float8 secs = PG_GETARG_FLOAT8(0); float8 endtime; + elog(FATAL, "FATAL from pg_sleep()"); + /* * We sleep using WaitLatch, to ensure that we'll wake up promptly if an * important signal (such as SIGALRM or SIGINT) arrives. Because diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c index 660cdec93c..64faad19df 100644 --- a/src/interfaces/libpq/fe-misc.c +++ b/src/interfaces/libpq/fe-misc.c @@ -749,8 +749,11 @@ retry4: */ definitelyEOF: libpq_append_conn_error(conn, "server closed the connection unexpectedly\n" - "\tThis probably means the server terminated abnormally\n" - "\tbefore or while processing the request."); + "\tThis probably means the server terminated%s\n" + "\tbefore or while processing the request.", + (conn->result == NULL) ? " null" : + (conn->result->resultStatus == PGRES_FATAL_ERROR) ? + "" : " abnormally"); /* Come here if lower-level code already set a suitable errorMessage */ definitelyFailed: diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c index 5613c56b14..03914b97fc 100644 --- a/src/interfaces/libpq/fe-protocol3.c +++ b/src/interfaces/libpq/fe-protocol3.c @@ -2158,6 +2158,7 @@ pqFunctionCall3(PGconn *conn, Oid fnid, if (pqGetErrorNotice3(conn, true)) continue; status = PGRES_FATAL_ERROR; + fprintf(stderr, "Got 'E'\n"); break; case 'A': /* notify message */ /* handle notify and go back to processing return values */ diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c index f1192d28f2..f4c7f51b0a 100644 --- a/src/interfaces/libpq/fe-secure-openssl.c +++ b/src/interfaces/libpq/fe-secure-openssl.c @@ -206,8 +206,11 @@ rloop: if (result_errno == EPIPE || result_errno == ECONNRESET) libpq_append_conn_error(conn, "server closed the connection unexpectedly\n" - "\tThis probably means the server terminated abnormally\n" - "\tbefore or while processing the request."); + "\tThis probably means the server terminated%s\n" + "\tbefore or while processing the request.", + (conn->result == NULL) ? " null" : + (conn->result->resultStatus == PGRES_FATAL_ERROR) ? + "" : " abnormally"); else libpq_append_conn_error(conn, "SSL SYSCALL error: %s", SOCK_STRERROR(result_errno, @@ -306,8 +309,11 @@ pgtls_write(PGconn *conn, const void *ptr, size_t len) result_errno = SOCK_ERRNO; if (result_errno == EPIPE || result_errno == ECONNRESET) libpq_append_conn_error(conn, "server closed the connection unexpectedly\n" - "\tThis probably means the server terminated abnormally\n" - "\tbefore or while processing the request."); + "\tThis probably means the server terminated%s\n" + "\tbefore or while processing the request.", + (conn->result == NULL) ? " null" : + (conn->result->resultStatus == PGRES_FATAL_ERROR) ? + "" : " abnormally"); else libpq_append_conn_error(conn, "SSL SYSCALL error: %s", SOCK_STRERROR(result_errno, diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c index bd72a87bbb..be93c2c0f9 100644 --- a/src/interfaces/libpq/fe-secure.c +++ b/src/interfaces/libpq/fe-secure.c @@ -233,8 +233,11 @@ pqsecure_raw_read(PGconn *conn, void *ptr, size_t len) case EPIPE: case ECONNRESET: libpq_append_conn_error(conn, "server closed the connection unexpectedly\n" - "\tThis probably means the server terminated abnormally\n" - "\tbefore or while processing the request."); + "\tThis probably means the server terminated%s\n" + "\tbefore or while processing the request.", + (conn->result == NULL) ? " null" : + (conn->result->resultStatus == PGRES_FATAL_ERROR) ? + "" : " abnormally"); break; default: @@ -395,8 +398,12 @@ retry_masked: /* (strdup failure is OK, we'll cope later) */ snprintf(msgbuf, sizeof(msgbuf), libpq_gettext("server closed the connection unexpectedly\n" - "\tThis probably means the server terminated abnormally\n" - "\tbefore or while processing the request.")); + "\tThis probably means the server terminated%s\n" + "\tbefore or while processing the request."), + (conn->result == NULL) ? " null" : + (conn->result->resultStatus == PGRES_FATAL_ERROR) ? + "" : " abnormally"); + /* keep newline out of translated string */ strlcat(msgbuf, "\n", sizeof(msgbuf)); conn->write_err_msg = strdup(msgbuf); --d8M1nhgBiD9I0Y+K--