| From: | Michael Paquier <michael(at)paquier(dot)xyz> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Make stringToNode() infrastructure thread-safe |
| Date: | 2026-08-24 03:18:06 |
| Message-ID: | E1wyLCH-00000001qcJ-2iGY@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Make stringToNode() infrastructure thread-safe
While stringToNode() was technically reentrant-safe, this was only for
single-threaded workloads: the string decoded was stored in a global
variable. This may be unsafe depending on the execution model, and
definitely unsafe in multi-threaded environments.
This patch moves the global variables into a struct (ReadNodeContext),
whose pointer is passed around on the stack. Support functions for node
read, extensible nodes (note: these have never been tested, should be
tested) and pg_strtok() are updated to handle the context data across
the call stack.
Code simplifications are mostly in stringToNodeInternal(), that can rely
on the context structure rather than a save-and-reassign logic based on
the global variables previously available.
Author: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
Reviewed-by: Peter Eisentraut <peter(at)eisentraut(dot)org>
Reviewed-by: Michael Paquier <michael(at)paquier(dot)xyz>
Reviewed-by: Yuhang Qiu <iamqyh(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAEze2WjsGnOM4MB+n1LLdhhUg6r=hwWZRv+-heDE4UtzRdgjyg@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/9673a0aa92f4fd75c564e2c8e14d71500a7b55ae
Modified Files
--------------
src/backend/nodes/gen_node_support.pl | 8 +-
src/backend/nodes/read.c | 76 +++++------------
src/backend/nodes/readfuncs.c | 152 +++++++++++++++++-----------------
src/include/nodes/extensible.h | 6 +-
src/include/nodes/readfuncs.h | 30 ++++---
src/tools/pgindent/typedefs.list | 1 +
6 files changed, 124 insertions(+), 149 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Daniel Gustafsson | 2026-08-24 08:11:18 | pgsql: Use ArchiveHandle.lookaheadSize instead of a hardcoded 512 |
| Previous Message | Michael Paquier | 2026-08-24 02:15:10 | pgsql: Move some node-read support functions from nodes.h to readfuncs. |