@@ -485,7 +485,23 @@ void cmd_recurse(mapcache_context *cmd_ctx, mapcache_tile *tile)
485485 if (sig_int_received || error_detected ) { //stop if we were asked to stop by hitting ctrl-c
486486 //remove all items from the queue
487487 struct seed_cmd entry ;
488- while (trypop_queue (& entry )!= APR_EAGAIN ) /*do nothing*/ ;
488+ int retry_count = 0 ;
489+ int ret = trypop_queue (& entry );
490+ while (ret != APR_EAGAIN ) {
491+ // try to empty queue with a graceful retreat up to 55 seconds
492+ // for retries before forcefully terminating threads
493+ if (ret == APR_EOF )
494+ break ;
495+ if (ret != APR_SUCCESS )
496+ retry_count ++ ;
497+ if (retry_count > 10 ) {
498+ printf ("Feed worker threads failed to terminate. Stopping forcefully.\n" );
499+ apr_queue_interrupt_all (work_queue );
500+ break ;
501+ }
502+ apr_sleep (retry_count * 1000000 );
503+ ret = trypop_queue (& entry );
504+ }
489505 return ;
490506 }
491507
@@ -614,7 +630,23 @@ void feed_worker()
614630 if (sig_int_received || error_detected ) { //stop if we were asked to stop by hitting ctrl-c
615631 //remove all items from the queue
616632 struct seed_cmd entry ;
617- while (trypop_queue (& entry )!= APR_EAGAIN ) /* do nothing */ ;
633+ int retry_count = 0 ;
634+ int ret = trypop_queue (& entry );
635+ while (ret != APR_EAGAIN ) {
636+ // try to empty queue with a graceful retreat up to 55 seconds
637+ // for retries before forcefully terminating threads
638+ if (ret == APR_EOF )
639+ break ;
640+ if (ret != APR_SUCCESS )
641+ retry_count ++ ;
642+ if (retry_count > 10 ) {
643+ printf ("Feed worker threads failed to terminate. Stopping forcefully.\n" );
644+ apr_queue_interrupt_all (work_queue );
645+ break ;
646+ }
647+ apr_sleep (retry_count * 1000000 );
648+ ret = trypop_queue (& entry );
649+ }
618650 break ;
619651 }
620652 if (iteration_mode == MAPCACHE_ITERATION_LOG ) {
0 commit comments