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 1m5U1P-0005dB-1H for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Jul 2021 14:13:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m5U1N-0003MH-FU for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Jul 2021 14:13:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5U1N-0003M9-7U for pgsql-hackers@lists.postgresql.org; Mon, 19 Jul 2021 14:13:25 +0000 Received: from mx0b-0050f201.pphosted.com ([148.163.141.54]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5U1I-0002LE-Bf for pgsql-hackers@postgresql.org; Mon, 19 Jul 2021 14:13:23 +0000 Received: from pps.filterd (m0203370.ppops.net [127.0.0.1]) by mx0b-0050f201.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 16JE2NrR032105 for ; Mon, 19 Jul 2021 23:13:19 +0900 Received: from sraihe.sra.co.jp (sraihe.sra.co.jp [221.255.117.38]) by mx0b-0050f201.pphosted.com with ESMTP id 39vjtqs5f9-1 for ; Mon, 19 Jul 2021 23:13:18 +0900 Received: from srascb.sra.co.jp (srascb [133.137.8.65]) by sraihe.sra.co.jp (Postfix) with ESMTP id 29CE52A684B for ; Mon, 19 Jul 2021 23:13:18 +0900 (JST) Received: from sranhm.sra.co.jp (osspc25 [133.137.174.97]) by srascb.sra.co.jp (Postfix) with ESMTP id EC6845800AB for ; Mon, 19 Jul 2021 23:13:17 +0900 (JST) Received: from yugon-CFSV7-1 (sraihb-hub.sra.co.jp [133.137.8.6]) by sranhm.sra.co.jp (Postfix) with SMTP id D2A9AA084E; Mon, 19 Jul 2021 23:13:17 +0900 (JST) Date: Mon, 19 Jul 2021 23:11:29 +0900 From: Yugo NAGATA To: Yugo NAGATA Cc: pgsql-hackers@postgresql.org Subject: Re: Question about non-blocking mode in libpq Message-Id: <20210719231129.b2ab655c0d0e80545274c86f@sraoss.co.jp> In-Reply-To: <20210713115949.702986955f8ccf23fa81073c@sraoss.co.jp> References: <20210713115949.702986955f8ccf23fa81073c@sraoss.co.jp> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Proofpoint-GUID: zGtksvumgQNJM6jjGbJa_0GfIGKGLU71 X-Proofpoint-ORIG-GUID: zGtksvumgQNJM6jjGbJa_0GfIGKGLU71 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=10049 signatures=668682 X-Proofpoint-Spam-Details: rule=spam_low_notspam policy=spam_low score=0 mlxscore=0 malwarescore=0 bulkscore=0 suspectscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 impostorscore=0 clxscore=1034 mlxlogscore=813 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107190083 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 13 Jul 2021 11:59:49 +0900 Yugo NAGATA wrote: > Hello, > > During reading the documentation of libpq [1] , I found the following > description: > > In the nonblocking state, calls to PQsendQuery, PQputline, PQputnbytes, > PQputCopyData, and PQendcopy will not block but instead return an error > if they need to be called again. > > [1] https://www.postgresql.org/docs/devel/libpq-async.html > > 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? I have further questions. Reading the following statement: "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? 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). /* * If data remains unsent, send it. Else we might be waiting for the * result of a command the backend hasn't even got yet. */ while ((flushResult = pqFlush(conn)) > 0) { if (pqWait(false, true, conn)) { flushResult = -1; break; } } Therefore, I wander the last paragraph of this section is now unnecessary. right? -- Yugo NAGATA