pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Avoid calling proc_exit() in processes forked by system(). 7+ messages / 1 participants [nested] [flat]
* pgsql: Avoid calling proc_exit() in processes forked by system(). @ 2023-10-17 15:44 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: Nathan Bossart @ 2023-10-17 15:44 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid calling proc_exit() in processes forked by system(). The SIGTERM handler for the startup process immediately calls proc_exit() for the duration of the restore_command, i.e., a call to system(). This system() call forks a new process to execute the shell command, and this child process inherits the parent's signal handlers. If both the parent and child processes receive SIGTERM, both will attempt to call proc_exit(). This can end badly. For example, both processes will try to remove themselves from the PGPROC shared array. To fix this problem, this commit adds a check in StartupProcShutdownHandler() to see whether MyProcPid == getpid(). If they match, this is the parent process, and we can proc_exit() like before. If they do not match, this is a child process, and we just emit a message to STDERR (in a signal safe manner) and _exit(), thereby skipping any problematic exit callbacks. This commit also adds checks in proc_exit(), ProcKill(), and AuxiliaryProcKill() that verify they are not being called within such child processes. Suggested-by: Andres Freund Reviewed-by: Thomas Munro, Andres Freund Discussion: https://postgr.es/m/Y9nGDSgIm83FHcad%40paquier.xyz Discussion: https://postgr.es/m/20230223231503.GA743455%40nathanxps13 Backpatch-through: 11 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/97550c0711972a9856b5db751539bbaf2f88884c Modified Files -------------- src/backend/postmaster/startup.c | 17 ++++++++++++++++- src/backend/storage/ipc/ipc.c | 4 ++++ src/backend/storage/lmgr/proc.c | 8 ++++++++ src/backend/utils/error/elog.c | 28 ++++++++++++++++++++++++++++ src/include/utils/elog.h | 6 ++++++ 5 files changed, 62 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Avoid calling proc_exit() in processes forked by system(). @ 2023-10-17 15:44 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: Nathan Bossart @ 2023-10-17 15:44 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid calling proc_exit() in processes forked by system(). The SIGTERM handler for the startup process immediately calls proc_exit() for the duration of the restore_command, i.e., a call to system(). This system() call forks a new process to execute the shell command, and this child process inherits the parent's signal handlers. If both the parent and child processes receive SIGTERM, both will attempt to call proc_exit(). This can end badly. For example, both processes will try to remove themselves from the PGPROC shared array. To fix this problem, this commit adds a check in StartupProcShutdownHandler() to see whether MyProcPid == getpid(). If they match, this is the parent process, and we can proc_exit() like before. If they do not match, this is a child process, and we just emit a message to STDERR (in a signal safe manner) and _exit(), thereby skipping any problematic exit callbacks. This commit also adds checks in proc_exit(), ProcKill(), and AuxiliaryProcKill() that verify they are not being called within such child processes. Suggested-by: Andres Freund Reviewed-by: Thomas Munro, Andres Freund Discussion: https://postgr.es/m/Y9nGDSgIm83FHcad%40paquier.xyz Discussion: https://postgr.es/m/20230223231503.GA743455%40nathanxps13 Backpatch-through: 11 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/ee06199fcb0a38abbb0f0745e66e6aa7150ee6ef Modified Files -------------- src/backend/postmaster/startup.c | 17 ++++++++++++++++- src/backend/storage/ipc/ipc.c | 4 ++++ src/backend/storage/lmgr/proc.c | 8 ++++++++ src/backend/utils/error/elog.c | 28 ++++++++++++++++++++++++++++ src/include/utils/elog.h | 6 ++++++ 5 files changed, 62 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Avoid calling proc_exit() in processes forked by system(). @ 2023-10-17 15:44 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: Nathan Bossart @ 2023-10-17 15:44 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid calling proc_exit() in processes forked by system(). The SIGTERM handler for the startup process immediately calls proc_exit() for the duration of the restore_command, i.e., a call to system(). This system() call forks a new process to execute the shell command, and this child process inherits the parent's signal handlers. If both the parent and child processes receive SIGTERM, both will attempt to call proc_exit(). This can end badly. For example, both processes will try to remove themselves from the PGPROC shared array. To fix this problem, this commit adds a check in StartupProcShutdownHandler() to see whether MyProcPid == getpid(). If they match, this is the parent process, and we can proc_exit() like before. If they do not match, this is a child process, and we just emit a message to STDERR (in a signal safe manner) and _exit(), thereby skipping any problematic exit callbacks. This commit also adds checks in proc_exit(), ProcKill(), and AuxiliaryProcKill() that verify they are not being called within such child processes. Suggested-by: Andres Freund Reviewed-by: Thomas Munro, Andres Freund Discussion: https://postgr.es/m/Y9nGDSgIm83FHcad%40paquier.xyz Discussion: https://postgr.es/m/20230223231503.GA743455%40nathanxps13 Backpatch-through: 11 Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/c9265ae80b6aa02daef620465800b03967433a39 Modified Files -------------- src/backend/postmaster/startup.c | 17 ++++++++++++++++- src/backend/storage/ipc/ipc.c | 4 ++++ src/backend/storage/lmgr/proc.c | 8 ++++++++ src/backend/utils/error/elog.c | 28 ++++++++++++++++++++++++++++ src/include/utils/elog.h | 6 ++++++ 5 files changed, 62 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Avoid calling proc_exit() in processes forked by system(). @ 2023-10-17 15:44 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: Nathan Bossart @ 2023-10-17 15:44 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid calling proc_exit() in processes forked by system(). The SIGTERM handler for the startup process immediately calls proc_exit() for the duration of the restore_command, i.e., a call to system(). This system() call forks a new process to execute the shell command, and this child process inherits the parent's signal handlers. If both the parent and child processes receive SIGTERM, both will attempt to call proc_exit(). This can end badly. For example, both processes will try to remove themselves from the PGPROC shared array. To fix this problem, this commit adds a check in StartupProcShutdownHandler() to see whether MyProcPid == getpid(). If they match, this is the parent process, and we can proc_exit() like before. If they do not match, this is a child process, and we just emit a message to STDERR (in a signal safe manner) and _exit(), thereby skipping any problematic exit callbacks. This commit also adds checks in proc_exit(), ProcKill(), and AuxiliaryProcKill() that verify they are not being called within such child processes. Suggested-by: Andres Freund Reviewed-by: Thomas Munro, Andres Freund Discussion: https://postgr.es/m/Y9nGDSgIm83FHcad%40paquier.xyz Discussion: https://postgr.es/m/20230223231503.GA743455%40nathanxps13 Backpatch-through: 11 Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/54fc9dca5b10e82cb85c7cd44ebe1eb0f28f795b Modified Files -------------- src/backend/postmaster/startup.c | 17 ++++++++++++++++- src/backend/storage/ipc/ipc.c | 4 ++++ src/backend/storage/lmgr/proc.c | 8 ++++++++ src/backend/utils/error/elog.c | 28 ++++++++++++++++++++++++++++ src/include/utils/elog.h | 6 ++++++ 5 files changed, 62 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Avoid calling proc_exit() in processes forked by system(). @ 2023-10-17 15:44 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: Nathan Bossart @ 2023-10-17 15:44 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid calling proc_exit() in processes forked by system(). The SIGTERM handler for the startup process immediately calls proc_exit() for the duration of the restore_command, i.e., a call to system(). This system() call forks a new process to execute the shell command, and this child process inherits the parent's signal handlers. If both the parent and child processes receive SIGTERM, both will attempt to call proc_exit(). This can end badly. For example, both processes will try to remove themselves from the PGPROC shared array. To fix this problem, this commit adds a check in StartupProcShutdownHandler() to see whether MyProcPid == getpid(). If they match, this is the parent process, and we can proc_exit() like before. If they do not match, this is a child process, and we just emit a message to STDERR (in a signal safe manner) and _exit(), thereby skipping any problematic exit callbacks. This commit also adds checks in proc_exit(), ProcKill(), and AuxiliaryProcKill() that verify they are not being called within such child processes. Suggested-by: Andres Freund Reviewed-by: Thomas Munro, Andres Freund Discussion: https://postgr.es/m/Y9nGDSgIm83FHcad%40paquier.xyz Discussion: https://postgr.es/m/20230223231503.GA743455%40nathanxps13 Backpatch-through: 11 Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/ac1dfc303d0e14cd095a71d1698cfc1fb8c34002 Modified Files -------------- src/backend/postmaster/startup.c | 17 ++++++++++++++++- src/backend/storage/ipc/ipc.c | 4 ++++ src/backend/storage/lmgr/proc.c | 8 ++++++++ src/backend/utils/error/elog.c | 28 ++++++++++++++++++++++++++++ src/include/utils/elog.h | 6 ++++++ 5 files changed, 62 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Avoid calling proc_exit() in processes forked by system(). @ 2023-10-17 15:44 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: Nathan Bossart @ 2023-10-17 15:44 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid calling proc_exit() in processes forked by system(). The SIGTERM handler for the startup process immediately calls proc_exit() for the duration of the restore_command, i.e., a call to system(). This system() call forks a new process to execute the shell command, and this child process inherits the parent's signal handlers. If both the parent and child processes receive SIGTERM, both will attempt to call proc_exit(). This can end badly. For example, both processes will try to remove themselves from the PGPROC shared array. To fix this problem, this commit adds a check in StartupProcShutdownHandler() to see whether MyProcPid == getpid(). If they match, this is the parent process, and we can proc_exit() like before. If they do not match, this is a child process, and we just emit a message to STDERR (in a signal safe manner) and _exit(), thereby skipping any problematic exit callbacks. This commit also adds checks in proc_exit(), ProcKill(), and AuxiliaryProcKill() that verify they are not being called within such child processes. Suggested-by: Andres Freund Reviewed-by: Thomas Munro, Andres Freund Discussion: https://postgr.es/m/Y9nGDSgIm83FHcad%40paquier.xyz Discussion: https://postgr.es/m/20230223231503.GA743455%40nathanxps13 Backpatch-through: 11 Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/e2e16904224a94bf514b67604b9c476c8a8154ac Modified Files -------------- src/backend/postmaster/startup.c | 15 ++++++++++++++- src/backend/storage/ipc/ipc.c | 4 ++++ src/backend/storage/lmgr/proc.c | 8 ++++++++ src/backend/utils/error/elog.c | 28 ++++++++++++++++++++++++++++ src/include/utils/elog.h | 6 ++++++ 5 files changed, 60 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Avoid calling proc_exit() in processes forked by system(). @ 2023-10-17 15:44 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: Nathan Bossart @ 2023-10-17 15:44 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid calling proc_exit() in processes forked by system(). The SIGTERM handler for the startup process immediately calls proc_exit() for the duration of the restore_command, i.e., a call to system(). This system() call forks a new process to execute the shell command, and this child process inherits the parent's signal handlers. If both the parent and child processes receive SIGTERM, both will attempt to call proc_exit(). This can end badly. For example, both processes will try to remove themselves from the PGPROC shared array. To fix this problem, this commit adds a check in StartupProcShutdownHandler() to see whether MyProcPid == getpid(). If they match, this is the parent process, and we can proc_exit() like before. If they do not match, this is a child process, and we just emit a message to STDERR (in a signal safe manner) and _exit(), thereby skipping any problematic exit callbacks. This commit also adds checks in proc_exit(), ProcKill(), and AuxiliaryProcKill() that verify they are not being called within such child processes. Suggested-by: Andres Freund Reviewed-by: Thomas Munro, Andres Freund Discussion: https://postgr.es/m/Y9nGDSgIm83FHcad%40paquier.xyz Discussion: https://postgr.es/m/20230223231503.GA743455%40nathanxps13 Backpatch-through: 11 Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/d0e7f95b48453703d7c740438198e47d03497cec Modified Files -------------- src/backend/postmaster/startup.c | 15 ++++++++++++++- src/backend/storage/ipc/ipc.c | 4 ++++ src/backend/storage/lmgr/proc.c | 8 ++++++++ src/backend/utils/error/elog.c | 28 ++++++++++++++++++++++++++++ src/include/utils/elog.h | 6 ++++++ 5 files changed, 60 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2023-10-17 15:44 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2023-10-17 15:44 pgsql: Avoid calling proc_exit() in processes forked by system(). Nathan Bossart <nathan@postgresql.org> 2023-10-17 15:44 pgsql: Avoid calling proc_exit() in processes forked by system(). Nathan Bossart <nathan@postgresql.org> 2023-10-17 15:44 pgsql: Avoid calling proc_exit() in processes forked by system(). Nathan Bossart <nathan@postgresql.org> 2023-10-17 15:44 pgsql: Avoid calling proc_exit() in processes forked by system(). Nathan Bossart <nathan@postgresql.org> 2023-10-17 15:44 pgsql: Avoid calling proc_exit() in processes forked by system(). Nathan Bossart <nathan@postgresql.org> 2023-10-17 15:44 pgsql: Avoid calling proc_exit() in processes forked by system(). Nathan Bossart <nathan@postgresql.org> 2023-10-17 15:44 pgsql: Avoid calling proc_exit() in processes forked by system(). Nathan Bossart <nathan@postgresql.org>
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