Skip to content

Commit a1dc976

Browse files
committed
try and address metris cleanup segmentation fault on shutdown; see #1207
by not flushing metrics to the shared memory segment upon exit Signed-off-by: Hans Zandbelt <[email protected]>
1 parent c375dba commit a1dc976

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
11/21/2024
22
- add option to set local address for outgoing HTTP requests; see #1283; thanks @studersi
33
using e.g. SetEnvIfExpr true OIDC_CURL_INTERFACE=192.168.10.2
4+
- try and address metris cleanup segmentation fault on shutdown; see #1207
5+
by not flushing metrics to the shared memory segment upon exit
46

57
11/14/2024
68
- allow specific settings Strict|Lax|None|Disabled for OIDCCookieSameSite in addition to On(=Lax)|Off(=None)

src/metrics.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,10 @@ static void *APR_THREAD_FUNC oidc_metrics_thread_run(apr_thread_t *thread, void
677677
while (_oidc_metrics_thread_exit == FALSE) {
678678

679679
apr_sleep(oidc_metrics_interval(s));
680-
// NB: no exit here because we need to write our local metrics into the cache before exiting
680+
681+
// NB: exit here because the parent thread may have cleaned up the shared memory segment
682+
if (_oidc_metrics_thread_exit == TRUE)
683+
break;
681684

682685
/* lock the mutex that protects the locally cached metrics */
683686
oidc_cache_mutex_lock(s->process->pool, s, _oidc_metrics_process_mutex);
@@ -778,17 +781,18 @@ apr_status_t oidc_metrics_child_init(apr_pool_t *p, server_rec *s) {
778781
* NB: global, yet called for each vhost that has metrics enabled!
779782
*/
780783
apr_status_t oidc_metrics_cleanup(server_rec *s) {
784+
apr_status_t rv = APR_SUCCESS;
781785

782786
/* make sure it gets executed exactly once! */
783-
if (_oidc_metrics_cache == NULL)
787+
if ((_oidc_metrics_cache == NULL) || (_oidc_metrics_thread_exit == TRUE) || (_oidc_metrics_thread == NULL))
784788
return APR_SUCCESS;
785789

786-
/* signal the collector thread to exit and wait (at max 5 seconds) for it to flush its data and exit */
790+
/* signal the collector thread to exit */
787791
_oidc_metrics_thread_exit = TRUE;
788-
apr_status_t rv = APR_SUCCESS;
789792
apr_thread_join(&rv, _oidc_metrics_thread);
790793
if (rv != APR_SUCCESS)
791-
return rv;
794+
oidc_serror(s, "apr_thread_join failed");
795+
_oidc_metrics_thread = NULL;
792796

793797
/* delete the shared memory segment if we are in the parent process */
794798
if (_oidc_metrics_is_parent == TRUE)
@@ -798,12 +802,14 @@ apr_status_t oidc_metrics_cleanup(server_rec *s) {
798802
/* delete the process mutex that guards the local metrics data */
799803
if (oidc_cache_mutex_destroy(s, _oidc_metrics_process_mutex) == FALSE)
800804
return APR_EGENERAL;
805+
_oidc_metrics_process_mutex = NULL;
801806

802807
/* delete the process mutex that guards the global shared memory segment */
803808
if (oidc_cache_mutex_destroy(s, _oidc_metrics_global_mutex) == FALSE)
804809
return APR_EGENERAL;
810+
_oidc_metrics_global_mutex = NULL;
805811

806-
return rv;
812+
return APR_SUCCESS;
807813
}
808814

809815
/*

src/mod_auth_openidc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,11 @@ static void oidc_child_init(apr_pool_t *p, server_rec *s) {
17841784
oidc_cfg_child_init(p, cfg, sp);
17851785
sp = sp->next;
17861786
}
1787-
apr_pool_cleanup_register(p, s, apr_pool_cleanup_null, oidc_cleanup_child);
1787+
/*
1788+
* NB: don't pass oidc_cleanup_child as the child cleanup routine parameter
1789+
* because that does not actually get called upon child cleanup...
1790+
*/
1791+
apr_pool_cleanup_register(p, s, oidc_cleanup_child, apr_pool_cleanup_null);
17881792
}
17891793

17901794
static const char oidcFilterName[] = "oidc_filter_in_filter";

0 commit comments

Comments
 (0)