From 97f9011a63010b43694dececbbe54840dd3c3b20 Mon Sep 17 00:00:00 2001 From: Anthonin Bonnefoy Date: Fri, 21 Jun 2024 09:40:13 +0200 Subject: [PATCH] Fix possible race condition when reading text file --- src/pg_tracing_sql_functions.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pg_tracing_sql_functions.c b/src/pg_tracing_sql_functions.c index f88b4f9..f9cdd09 100644 --- a/src/pg_tracing_sql_functions.c +++ b/src/pg_tracing_sql_functions.c @@ -251,6 +251,14 @@ pg_tracing_spans(PG_FUNCTION_ARGS) return (Datum) 0; LWLockAcquire(pg_tracing_shared_state->lock, lock_mode); + /* There was a new write, reload the text file */ + if (pg_tracing_shared_state->extent != qbuffer_size) + { + free(qbuffer); + qbuffer = qtext_load_file(&qbuffer_size); + } + Assert(pg_tracing_shared_state->extent == qbuffer_size); + for (int i = 0; i < shared_spans->end; i++) { span = shared_spans->spans + i;