From c7abdfb3e404a8a238e8352ea5e195f864efefd2 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 5 Dec 2016 10:10:24 +0100 Subject: indexamajig: Add ping mechanism to avoid timing out when trying lots of indexers --- src/im-sandbox.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/im-sandbox.c') diff --git a/src/im-sandbox.c b/src/im-sandbox.c index 979fc136..df8ed1e2 100644 --- a/src/im-sandbox.c +++ b/src/im-sandbox.c @@ -78,6 +78,7 @@ struct sandbox pid_t *pids; int *running; time_t *last_response; + int last_ping[MAX_NUM_WORKERS]; /* Streams to read from (NB not the same indices as the above) */ int n_read; @@ -123,6 +124,7 @@ static time_t get_monotonic_seconds() static void stamp_response(struct sandbox *sb, int n) { sb->last_response[n] = get_monotonic_seconds(); + sb->last_ping[n] = sb->shared->pings[n]; } @@ -131,13 +133,20 @@ static void check_hung_workers(struct sandbox *sb) int i; time_t tnow = get_monotonic_seconds(); for ( i=0; in_proc; i++ ) { + if ( !sb->running[i] ) continue; + + if ( sb->shared->pings[i] != sb->last_ping[i] ) { + stamp_response(sb, i); + } + if ( tnow - sb->last_response[i] > 240 ) { STATUS("Worker %i did not respond for 240 seconds - " "sending it SIGKILL.\n", i); kill(sb->pids[i], SIGKILL); stamp_response(sb, i); } + } } @@ -534,6 +543,9 @@ static void start_worker_process(struct sandbox *sb, int slot) return; } + sb->shared->pings[slot] = 0; + sb->last_ping[slot] = 0; + p = fork(); if ( p == -1 ) { ERROR("fork() failed!\n"); -- cgit v1.2.3