pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@kurilemu.de>
To: Michael Paquier <michael@paquier.xyz>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: euler@eulerto.com
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: NULL pointer dereference in syslogger with load_libraries() and -DEXEC_BACKEND at startup
Date: Tue, 26 May 2026 13:09:13 +0200
Message-ID: <ahV9KzLOqvOw78C3@alvherre.pgsql> (raw)
In-Reply-To: <ahU1AIsL3QJOONRG@paquier.xyz>

On 2026-May-26, Michael Paquier wrote:

> This issue is different, it is a Postgres logic bug, so adding an
> exception like the one you are suggesting is just a shortcut hiding
> the real issue: the log file is not ready yet, but the syslogger is
> invoked at a point when it thinks the log file exists.

I think we can solve this easily by flipping a new Boolean value at the
same point were MyBackendType was previously set.  The attached POC
fixes the scenario you described; can you confirm?  It needs some
additional comments, of course.

(There is one more place in elog.c where we check that MyBackendType is
_not_ B_LOGGER, but I think that one is correct as-is; and I'm wondering
if that would behave correctly before 0c8e082fba8d.)

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
“Cuando no hay humildad las personas se degradan” (A. Christie)

Attachments:

0001-POC-syslogger-add-Boolean-state-indicating-readiness.patch (text/x-diff, 2.7K) download From 3fee63b168279acb6556525b879559c03427ac14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvherre@kurilemu.de> Date: Tue, 26 May 2026 12:45:01 +0200 Subject: [PATCH] POC: syslogger: add Boolean state indicating readiness This replaces a comparison of MyBackendType, which was made obsolete by commit 0c8e082fba8d. --- src/backend/postmaster/syslogger.c | 5 +++++ src/backend/utils/error/elog.c | 6 +++--- src/include/postmaster/syslogger.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c index acfe0a01715..d736f6a4fab 100644 --- a/src/backend/postmaster/syslogger.c +++ b/src/backend/postmaster/syslogger.c @@ -76,6 +76,9 @@ char *Log_filename = NULL; bool Log_truncate_on_rotation = false; int Log_file_mode = S_IRUSR | S_IWUSR; +/* for elog.c */ +bool syslogger_setup_done = false; + /* * Private state */ @@ -195,6 +198,8 @@ SysLoggerMain(const void *startup_data, size_t startup_data_len) Assert(startup_data_len == 0); #endif + syslogger_setup_done = true; + /* * Now that we're done reading the startup data, release postmaster's * working memory context. diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 50c53b571a0..a6936a0c664 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -3831,7 +3831,7 @@ send_message_to_server_log(ErrorData *edata) * pipe). If this is not possible, fallback to an entry written to * stderr. */ - if (redirection_done || MyBackendType == B_LOGGER) + if (redirection_done || syslogger_setup_done) write_csvlog(edata); else fallback_to_stderr = true; @@ -3845,7 +3845,7 @@ send_message_to_server_log(ErrorData *edata) * pipe). If this is not possible, fallback to an entry written to * stderr. */ - if (redirection_done || MyBackendType == B_LOGGER) + if (redirection_done || syslogger_setup_done) { write_jsonlog(edata); } @@ -3885,7 +3885,7 @@ send_message_to_server_log(ErrorData *edata) } /* If in the syslogger process, try to write messages direct to file */ - if (MyBackendType == B_LOGGER) + if (syslogger_setup_done) write_syslogger_file(buf.data, buf.len, LOG_DESTINATION_STDERR); /* No more need of the message formatted for stderr */ diff --git a/src/include/postmaster/syslogger.h b/src/include/postmaster/syslogger.h index 30c4b2daf3f..44409fc2542 100644 --- a/src/include/postmaster/syslogger.h +++ b/src/include/postmaster/syslogger.h @@ -85,6 +85,7 @@ extern PGDLLIMPORT int syslogPipe[2]; extern PGDLLIMPORT HANDLE syslogPipe[2]; #endif +extern bool syslogger_setup_done; extern int SysLogger_Start(int child_slot); -- 2.47.3

view thread (25+ messages)  latest in thread

Message-ID: <ahV9KzLOqvOw78C3@alvherre.pgsql>
Permalink:  ../ahV9KzLOqvOw78C3@alvherre.pgsql/
Also on:    postgresql.org/message-id/ahV9KzLOqvOw78C3@alvherre.pgsql

 ·  · 

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-hackers@postgresql.org
  Cc: alvherre@kurilemu.de, michael@paquier.xyz, horikyota.ntt@gmail.com, euler@eulerto.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: NULL pointer dereference in syslogger with load_libraries() and -DEXEC_BACKEND at startup
  In-Reply-To: <ahV9KzLOqvOw78C3@alvherre.pgsql>

* 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