Skip to content

Commit

Permalink
mapcache_seed: try to kill still running threads after grace period (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
marisn authored Sep 27, 2023
1 parent 0b85061 commit 9f4cf0e
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions util/mapcache_seed.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,23 @@ void cmd_recurse(mapcache_context *cmd_ctx, mapcache_tile *tile)
if(sig_int_received || error_detected) { //stop if we were asked to stop by hitting ctrl-c
//remove all items from the queue
struct seed_cmd entry;
while (trypop_queue(&entry)!=APR_EAGAIN) /*do nothing*/;
int retry_count = 0;
int ret = trypop_queue(&entry);
while (ret != APR_EAGAIN) {
// try to empty queue with a graceful retreat up to 55 seconds
// for retries before forcefully terminating threads
if (ret == APR_EOF)
break;
if (ret != APR_SUCCESS)
retry_count++;
if (retry_count > 10) {
printf("Feed worker threads failed to terminate. Stopping forcefully.\n");
apr_queue_interrupt_all(work_queue);
break;
}
apr_sleep(retry_count * 1000000);
ret = trypop_queue(&entry);
}
return;
}

Expand Down Expand Up @@ -614,7 +630,23 @@ void feed_worker()
if(sig_int_received || error_detected) { //stop if we were asked to stop by hitting ctrl-c
//remove all items from the queue
struct seed_cmd entry;
while (trypop_queue(&entry)!=APR_EAGAIN) /* do nothing */;
int retry_count = 0;
int ret = trypop_queue(&entry);
while (ret != APR_EAGAIN) {
// try to empty queue with a graceful retreat up to 55 seconds
// for retries before forcefully terminating threads
if (ret == APR_EOF)
break;
if (ret != APR_SUCCESS)
retry_count++;
if (retry_count > 10) {
printf("Feed worker threads failed to terminate. Stopping forcefully.\n");
apr_queue_interrupt_all(work_queue);
break;
}
apr_sleep(retry_count * 1000000);
ret = trypop_queue(&entry);
}
break;
}
if(iteration_mode == MAPCACHE_ITERATION_LOG) {
Expand Down

0 comments on commit 9f4cf0e

Please sign in to comment.