pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: libpq: Add encrypted and non-blocking query cancellation routine
Date: Tue, 12 Mar 2024 16:40:56 +0000
Message-ID: <E1rk5BP-003RWD-U4@gemulon.postgresql.org> (raw)

libpq: Add encrypted and non-blocking query cancellation routines

The existing PQcancel API uses blocking IO, which makes PQcancel
impossible to use in an event loop based codebase without blocking the
event loop until the call returns.  It also doesn't encrypt the
connection over which the cancel request is sent, even when the original
connection required encryption.

This commit adds a PQcancelConn struct and assorted functions, which
provide a better mechanism of sending cancel requests; in particular all
the encryption used in the original connection are also used in the
cancel connection.  The main entry points are:

- PQcancelCreate creates the PQcancelConn based on the original
  connection (but does not establish an actual connection).
- PQcancelStart can be used to initiate non-blocking cancel requests,
  using encryption if the original connection did so, which must be
  pumped using
- PQcancelPoll.
- PQcancelReset puts a PQcancelConn back in state so that it can be
  reused to send a new cancel request to the same connection.
- PQcancelBlocking is a simpler-to-use blocking API that still uses
  encryption.

Additional functions are
 - PQcancelStatus, mimicks PQstatus;
 - PQcancelSocket, mimicks PQcancelSocket;
 - PQcancelErrorMessage, mimicks PQerrorMessage;
 - PQcancelFinish, mimicks PQfinish.

Author: Jelte Fennema-Nio <postgres@jeltef.nl>
Reviewed-by: Denis Laxalde <denis.laxalde@dalibo.com>
Discussion: https://postgr.es/m/AM5PR83MB0178D3B31CA1B6EC4A8ECC42F7529@AM5PR83MB0178.EURPRD83.prod.outlook.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/61461a300c1cb5d53955ecd792ad0ce75a104736

Modified Files
--------------
doc/src/sgml/libpq.sgml                          | 507 +++++++++++++++++++++--
src/interfaces/libpq/exports.txt                 |   9 +
src/interfaces/libpq/fe-cancel.c                 | 296 ++++++++++++-
src/interfaces/libpq/fe-connect.c                | 129 +++++-
src/interfaces/libpq/libpq-fe.h                  |  31 +-
src/interfaces/libpq/libpq-int.h                 |   5 +
src/test/modules/libpq_pipeline/libpq_pipeline.c | 121 ++++++
src/tools/pgindent/typedefs.list                 |   1 +
8 files changed, 1044 insertions(+), 55 deletions(-)



Message-ID: <E1rk5BP-003RWD-U4@gemulon.postgresql.org>
Permalink:  ../E1rk5BP-003RWD-U4@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1rk5BP-003RWD-U4@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: alvherre@alvh.no-ip.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: libpq: Add encrypted and non-blocking query cancellation routine
  In-Reply-To: <E1rk5BP-003RWD-U4@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox