Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nFcoa-0007m5-Js for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Feb 2022 14:10:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nFcoZ-00085C-Fw for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Feb 2022 14:10:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nFcoZ-000853-6W for pgsql-hackers@lists.postgresql.org; Thu, 03 Feb 2022 14:10:23 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nFcoW-0002Jj-01 for pgsql-hackers@postgresql.org; Thu, 03 Feb 2022 14:10:22 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 5798F32022CF; Thu, 3 Feb 2022 09:10:17 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 03 Feb 2022 09:10:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=UYF9rOv81lSn2FiRBdB/a6auafMMfWhDZCR3xL5Ug 6E=; b=cMB9tkcq1ZeKBS5KaIcpoHN6iR3kMu4ZxokWu4YdLknqDIv+AdJ5ZNuGa IaSiDf16zTQ1q4ZfcdzhHycWIYMW9a5gUQ7YN8YM8mGbRJTz7yIv2Ee7sAE771He Q2wioE1Mm3gHGMJMWMTLnmm8jMMl1pkt+A6KH4xyF2bu+VL7HykE8JMHm4M5IUz1 B03zx97SU3nmjf9jdZMeTsRktHOVmO3Mx8SbOWpn5Kp7PQEeeFOgBHrORKDbjxfP bEQkgLuxeVyS5nsJFMG8cArNh8c1WCOiiHhDgI9Evzejfr2YpWrgyZ287xpxpM4m 8VxJmKdNDNsAajjVOTcoc9TR5/NpA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrgeejgdehkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuhfhfvfgjtgfgsehtkeertddtfeejnecuhfhrohhmpefrvghtvghr ucfgihhsvghnthhrrghuthcuoehpvghtvghrrdgvihhsvghnthhrrghuthesvghnthgvrh hprhhishgvuggsrdgtohhmqeenucggtffrrghtthgvrhhnpeegudeuhfegiefhvdfgkedu leeguedtgfekgedvjedujeeuuedvgffhtdehfffhveenucffohhmrghinhepphhoshhtgh hrvghsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghi lhhfrhhomhepphgvthgvrhdrvghishgvnhhtrhgruhhtsegvnhhtvghrphhrihhsvggusg drtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 3 Feb 2022 09:10:15 -0500 (EST) Message-ID: <22d52a5b-31ce-d951-1f5f-3403d793cec3@enterprisedb.com> Date: Thu, 3 Feb 2022 15:10:14 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 Subject: Re: libpq async duplicate error results Content-Language: en-US From: Peter Eisentraut Cc: Fabien COELHO , pgsql-hackers References: To: Tom Lane In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tom, you worked on reorganzing the error message handling in libpq in PostgreSQL 14 (commit ffa2e4670123124b92f037d335a1e844c3782d3f). Any thoughts on this? On 25.01.22 09:32, Peter Eisentraut wrote: > > This issue was discovered by Fabien in the SHOW_ALL_RESULTS thread.  I'm > posting it here separately, because I think it ought to be addressed in > libpq rather than with a workaround in psql, as proposed over there. > > When using PQsendQuery() + PQgetResult() and the server crashes during > the execution of the command, PQgetResult() then returns two result sets > with partially duplicated error messages, like this from the attached > test program: > > command = SELECT 'before'; > result 1 status = PGRES_TUPLES_OK > error message = "" > > command = SELECT pg_terminate_backend(pg_backend_pid()); > result 1 status = PGRES_FATAL_ERROR > error message = "FATAL:  terminating connection due to administrator > command > " > result 2 status = PGRES_FATAL_ERROR > error message = "FATAL:  terminating connection due to administrator > command > server closed the connection unexpectedly >     This probably means the server terminated abnormally >     before or while processing the request. > " > > command = SELECT 'after'; > PQsendQuery() error: no connection to the server > > > This is hidden in normal use because PQexec() throws away all but the > last result set, but the extra one is still generated internally. > > Apparently, this has changed between PG13 and PG14.  In PG13 and > earlier, the output is > > command = SELECT 'before'; > result 1 status = PGRES_TUPLES_OK > error message = "" > > command = SELECT pg_terminate_backend(pg_backend_pid()); > result 1 status = PGRES_FATAL_ERROR > error message = "FATAL:  terminating connection due to administrator > command > " > result 2 status = PGRES_FATAL_ERROR > error message = "server closed the connection unexpectedly >     This probably means the server terminated abnormally >     before or while processing the request. > " > > command = SELECT 'after'; > PQsendQuery() error: no connection to the server > > In PG13, PQexec() concatenates all the error messages from multiple > results, so a user of PQexec() sees the same output before and after. > But for users of the lower-level APIs, things have become a bit more > confusing. > > Also, why are there multiple results being generated in the first place? > > > [0]: > https://www.postgresql.org/message-id/alpine.DEB.2.22.394.2112230703530.2668598@pseudo