Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZKTmU-0004zk-6a for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Jul 2015 16:00:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZKTmT-0006ZR-Jw for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Jul 2015 16:00:33 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZKTmS-0006Yp-Tj for pgsql-bugs@postgresql.org; Wed, 29 Jul 2015 16:00:33 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZKTmQ-0007Nz-AR for pgsql-bugs@postgresql.org; Wed, 29 Jul 2015 16:00:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t6TG0R2p031146; Wed, 29 Jul 2015 12:00:27 -0400 From: Tom Lane To: Niall Ross cc: Kevin Grittner , "pgsql-bugs@postgresql.org" Subject: Re: BUG #13518: CancelRequest lacks statement identifier In-reply-to: <55B7F554.7040700@btinternet.com> References: <20150724180236.2737.27011@wrigleys.postgresql.org> <773925395.3977925.1438112478191.JavaMail.yahoo@mail.yahoo.com> <26896.1438113446@sss.pgh.pa.us> <55B7F554.7040700@btinternet.com> Comments: In-reply-to Niall Ross message dated "Tue, 28 Jul 2015 22:34:12 +0100" Date: Wed, 29 Jul 2015 12:00:27 -0400 Message-ID: <31145.1438185627@sss.pgh.pa.us> X-Pg-Spam-Score: -3.3 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Niall Ross writes: > Am I misunderstanding something? My experience with using Postgres, and > my reading of the documents, is that a new statement, but not a new > connection, is needed to cancel a statement on that connection. The > cancel is signalled by a fresh statement using the same connection (and > specifically that connection's PID and Key). Uh, no, that's not how it works at all. PQcancel() involves opening a fresh connection to the postmaster, which will then send SIGINT to the backend process you're originally connected to. Also, looking again at the PQcancel code, I'm unsure that there is any actual race condition here. The comments therein quoth * Wait for the postmaster to close the connection, which indicates that * it's processed the request. Without this delay, we might issue another * command only to find that our cancel zaps that command instead of the * one we thought we were canceling. Note we don't actually expect this * read to obtain any data, we are just waiting for EOF to be signaled. which means that by the time the PQcancel call returns, the SIGINT has been sent. I did speculate upthread that delivery of that signal might be asynchronous, but that was just speculation. Even if there was some delay, the backend would ignore the signal unless it arrived later than the first byte of the next client request. So it seems a bit hard to credit that you would have a practical problem unless your application were to issue a new command while PQcancel was still executing ... and if it does, I maintain that's an application bug not a protocol problem. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs