From 5e0391392aca031c601f79e885452bb82ad909d1 Mon Sep 17 00:00:00 2001 From: Maheedhar PV Date: Mon, 13 Mar 2023 05:18:18 +0530 Subject: [PATCH] Out of on_proc_exit slots on guc license change Problem: When the guc timescaledb.license = 'timescale' is set in the conf file and a SIGHUP is sent to postgress process and a reload of the tsl module is triggered. This reload happens in 2 phases 1. tsl_module_load is called which will load the module only if not already loaded and 2.The ts_module_init is called for every ts_license_guc_assign_hook irrespective of if it is new load.This ts_module_init initialization function also registers a on_proc_exit function to be called on exit. The list of on_proc_exit methods are maintained in a fixed array on_proc_exit_list of size MAX_ON_EXITS (20) which gets filled up on repeated SIGHUPs and hence an error. Fix: The fix is to make the ts_module_init() register the on_proc_exit callback, only in case the module is reloaded and not in every init call. Closes #5233 --- CHANGELOG.md | 4 +++- src/license_guc.c | 8 +++++++- tsl/src/init.c | 4 +++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df597e75d..7842d6312 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,10 +13,12 @@ accidentally triggering the load of a previous DB version.** **Bugfixes** * #5396 Fix SEGMENTBY columns predicates to be pushed down -* #5410 Fix file trailer handling in the COPY fetcher +* #5410 Fix file trailer handling in the COPY fetcher +* #5233 Out of on_proc_exit slots on guc license change **Thanks** * @nikolaps for reporting an issue with the COPY fetcher +* @S-imo-n for reporting the issue on Background Worker Scheduler crash ## 2.10.1 (2023-03-07) diff --git a/src/license_guc.c b/src/license_guc.c index baa49be5a..0c1c623f5 100644 --- a/src/license_guc.c +++ b/src/license_guc.c @@ -20,6 +20,7 @@ static bool load_enabled = false; static GucSource load_source = PGC_S_DEFAULT; static void *tsl_handle = NULL; static PGFunction tsl_init_fn = NULL; +static bool tsl_register_proc_exit = false; /* * License Functions. @@ -128,6 +129,8 @@ tsl_module_load(void) return false; tsl_init_fn = function; tsl_handle = handle; + /* the on_proc_exit callback is registered by the tsl_init_fn after load */ + tsl_register_proc_exit = true; return true; } @@ -136,7 +139,10 @@ tsl_module_init(void) { Assert(tsl_handle != NULL); Assert(tsl_init_fn != NULL); - DirectFunctionCall1(tsl_init_fn, CharGetDatum(0)); + DirectFunctionCall1(tsl_init_fn, BoolGetDatum(tsl_register_proc_exit)); + /* register the on_proc_exit only when the module is reloaded */ + if (tsl_register_proc_exit) + tsl_register_proc_exit = false; } /* diff --git a/tsl/src/init.c b/tsl/src/init.c index 105224c3e..3fbe69393 100644 --- a/tsl/src/init.c +++ b/tsl/src/init.c @@ -255,6 +255,7 @@ TS_FUNCTION_INFO_V1(ts_module_init); PGDLLEXPORT Datum ts_module_init(PG_FUNCTION_ARGS) { + bool register_proc_exit = PG_GETARG_BOOL(0); ts_cm_functions = &tsl_cm_functions; _continuous_aggs_cache_inval_init(); @@ -264,7 +265,8 @@ ts_module_init(PG_FUNCTION_ARGS) _remote_dist_txn_init(); _tsl_process_utility_init(); /* Register a cleanup function to be called when the backend exits */ - on_proc_exit(ts_module_cleanup_on_pg_exit, 0); + if (register_proc_exit) + on_proc_exit(ts_module_cleanup_on_pg_exit, 0); PG_RETURN_BOOL(true); }