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 1m5sFH-0007ao-LD for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jul 2021 16:05:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m5sFF-0007dh-9q for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jul 2021 16:05:21 +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 1m5sFF-0007dZ-1v for pgsql-hackers@lists.postgresql.org; Tue, 20 Jul 2021 16:05:21 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5sFC-00062O-7h for pgsql-hackers@postgresql.org; Tue, 20 Jul 2021 16:05:20 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id B12F83200927; Tue, 20 Jul 2021 12:05:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 20 Jul 2021 12:05:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=Zk0vPdNvay/vWalElJKFIcuVqn3RauwYMSNESopIc1U=; b=Y9fYkUJW 0JOaHnqek0Ddom0npJPB9vngpmkBHMoQWUQXX16mEmJvMYpRH5Hvrxl8Z+wJMrwC 9VJGgrpGO4tggRtZnEin9PVMvvDTPY/4X2fdWPB/sHixImjaSgMPrxG/PYJK9L1O hpH95xx1dv0ux1+JrcePvSmUmQFGwNGL2/08T8X2ClrNzH7oclnBR4BmlGfjj/s4 R2NgVjDcjH+VCEkofApy8VvgnWrE/eqUkx0x0sfbZ7NgGEkDrG0EI8aM9nDvk8Sr G+zBEiwKs4aCROOnIoQ1Lkxy0UY8nZYV1Zb/vsd9VDJUWBfKgwaqHjbfDlQWVhGy QtKMMq1u2tpGWg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrfedvgdelgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgheqne cuggftrfgrthhtvghrnhepudejveejffejveduudetvdekieeuiedtvdeileefkeevjedu feeguedvjefhueelnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomhenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgv rhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 20 Jul 2021 12:05:14 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 9B2CD2A077A; Tue, 20 Jul 2021 12:05:11 -0400 (-04) Date: Tue, 20 Jul 2021 12:05:11 -0400 From: Alvaro Herrera To: Yugo NAGATA Cc: pgsql-hackers@postgresql.org Subject: Re: Question about non-blocking mode in libpq Message-ID: <202107201605.b3hmz4g6uqqz@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210719231129.b2ab655c0d0e80545274c86f@sraoss.co.jp> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-Jul-19, Yugo NAGATA wrote: > On Tue, 13 Jul 2021 11:59:49 +0900 > Yugo NAGATA wrote: > > However, looking into the code, PQsendQuery seems not to return an error > > in non-bloking mode even if unable to send all data. In such cases, > > pqSendSome will return 1 but it doesn't cause an error. Moreover, > > we would not need to call PQsendQuery again. Indead, we need to call > > PQflush until it returns 0, as documented with regard to PQflush. > > > > Do we need to fix the description of PQsetnonblocking? Yeah, I think you're right -- these functions don't error out, the commands are just stored locally in the output buffer. > "In the nonblocking state, calls to PQsendQuery, PQputline, PQputnbytes, > PQputCopyData, and PQendcopy will not block" > > this seems to me that this is a list of functions that could block in blocking > mode, but I wander PQflush also could block because it calls pqSendSome, right? I don't see that. If pqSendSome can't write anything, it'll just return 1. > Also, in the last paragraph of the section, I can find the following: > > "After sending any command or data on a nonblocking connection, call PQflush. ..." > > However, ISTM we don't need to call PQflush in non-bloking mode and we can > call PQgetResult immediately because PQgetResult internally calls pqFlush > until it returns 0 (or -1). Well, maybe you don't *need* to PQflush(); but if you don't call it, then the commands will sit in the output buffer indefinitely, which means the server won't execute them. So even if it works to just call PQgetResult and have it block, surely you would like to only call PQgetResult when the query has already been executed and the result already been received and processed; that is, so that you can call PQgetResult and obtain the result immediately, and avoid (say) blocking a GUI interface while PQgetResult flushes the commands out, the server executes the query and sends the results back. > Therefore, I wander the last paragraph of this section is > now unnecessary. right? Doesn't seem so to me. -- Álvaro Herrera 39°49'30"S 73°17'W — https://www.EnterpriseDB.com/