@@ -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 */
780783apr_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/*
0 commit comments