From: | Mats Kindahl <mats(at)timescale(dot)com> |
---|---|
To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Use of signal-unsafe functions from signal handlers |
Date: | 2022-05-24 09:42:35 |
Message-ID: | CA+14425wJh3m2XA4c8-stRKGQYLwKqFiScqZm7BBt1JxU2iU-g@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Hi all,
Typically, signal-unsafe functions should not be called from signal
handlers. In particular, calling malloc() directly or indirectly can cause
deadlocks, making PostgreSQL unresponsive to signals.
Unless I am missing something, bgworker_die uses ereport, which indirectly
calls printf-like functions, which are not signal-safe since they use
malloc(). In rare cases, this can lead to deadlocks with stacks that look
like this (from https://github.com/timescale/timescaledb/issues/4200)
#0 0x00007f0e4d1040eb in __lll_lock_wait_private () from
target:/lib/x86_64-linux-gnu/libc.so.6
[...]
#3 malloc (size=53)
[...]
#7 0x000055b9212235b1 in errmsg ()
#8 0x00007f0e27bf27a8 in handle_sigterm (postgres_signal_arg=15) at
/build/timescaledb/src/bgw/scheduler.c:841
#9 <signal handler called>
[...]
#13 free (ptr=<optimized out>)
#14 0x00007f0e4db12cb4 in OPENSSL_LH_free () from
target:/lib/x86_64-linux-gnu/libcrypto.so.1.1
[...]
A simple fix for this is to introduce a signal-safe version of write_stderr
and use that from bgworker_die, which the attached patch does. Am I missing
something or is this a bug?
Best wishes,
Mats Kindahl (Timescale)
Attachment | Content-Type | Size |
---|---|---|
0001-Add-signal-safe-function-to-write-to-log.patch | text/x-patch | 3.7 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Andrey Borodin | 2022-05-24 10:08:33 | Re: BUG #17485: Records missing from Primary Key index when doing REINDEX INDEX CONCURRENTLY |
Previous Message | Amit Kapila | 2022-05-24 09:38:41 | Re: How is this possible "publication does not exist" |