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 <[email protected]> Reviewed-by: Peter Eisentraut <[email protected]> Reviewed-by: Michael Paquier <[email protected]> Reviewed-by: Yuhang Qiu <[email protected]> Discussion: https://postgr.es/m/CAEze2WjsGnOM4MB+n1LLdhhUg6r=hwwzrv+-hede4utzrdg...@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(-)
