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 1nCHG4-0000Tj-Ks for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Jan 2022 08:32:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nCHG2-0007d6-1z for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Jan 2022 08:32:54 +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 1nCHG1-0007cx-4h for pgsql-hackers@lists.postgresql.org; Tue, 25 Jan 2022 08:32:53 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCHFv-0001c9-QP for pgsql-hackers@postgresql.org; Tue, 25 Jan 2022 08:32:52 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 6AE9A320206E; Tue, 25 Jan 2022 03:32:44 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 25 Jan 2022 03:32:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=s13uBsPDal5EUjA4JBVG+EHo1wTVABqxbPekJsROr VA=; b=fDxeptRYce7NO1JMOGyfGf2uxHugPe7qB3sjgB7cRSr+G1v/6uEE6LOLU 8EfGAsv0qXwpsZZKrE8+MGuFEQwZSXnBKavW9DXuq/hR0IhbE5FFGpII6QBDNyGx RWnB00sEuxM0uCXv5jPHUZEDAgAcfAdXExDFn21sz2E/5sCu1NjyD2J4oLzMS1Jd zcriJHg19ikA/FUSp0+sz1+8hLsDSSDJjTIKNkEnJlKLIxLYJghcQu0XdEoPXdvE YpmAafszsPN8YEh//xHkBAzLK70lzSC33V8ook5YxapLa8rIFjFhjMAAMpVAgQMJ 5f4UQikXJo1vyBEunaF2JdfYGAWsg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrvdekgdduvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurheptgfkffggfgfhuffvsehmtderredtfeejnecuhfhrohhmpefrvghtvghrucfg ihhsvghnthhrrghuthcuoehpvghtvghrrdgvihhsvghnthhrrghuthesvghnthgvrhhprh hishgvuggsrdgtohhmqeenucggtffrrghtthgvrhhnpeeijeevieduueehudehuddtffei jeejteeijeehhfevueeftdffjeeilefhleekffenucffohhmrghinhepphhoshhtghhrvg hsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhf rhhomhepphgvthgvrhdrvghishgvnhhtrhgruhhtsegvnhhtvghrphhrihhsvggusgdrtg homh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 25 Jan 2022 03:32:42 -0500 (EST) Content-Type: multipart/mixed; boundary="------------4bbkUbd0RiD1OrYcn0oTRyCh" Message-ID: Date: Tue, 25 Jan 2022 09:32:41 +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.0 Content-Language: en-US From: Peter Eisentraut Subject: libpq async duplicate error results To: pgsql-hackers Cc: Fabien COELHO List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------4bbkUbd0RiD1OrYcn0oTRyCh Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------4bbkUbd0RiD1OrYcn0oTRyCh Content-Type: text/plain; charset=UTF-8; name="test.c" Content-Disposition: attachment; filename="test.c" Content-Transfer-Encoding: base64 I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxsaWJwcS1mZS5oPgoKc3RhdGljIHZvaWQK cnVuX3F1ZXJ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