child_kill_children(): use method that actually works

it turned out that close()ing an fd behind the back of a thread
doesn't actually cause blocking operations to get a read/write event,
because the fd will stay valid to in-progress operations.
master
rofl0r 2020-09-17 21:13:28 +01:00
parent da1bc1425d
commit d4ef2cfa62
1 changed files with 11 additions and 7 deletions

View File

@ -222,20 +222,24 @@ oom:
*/
void child_kill_children (int sig)
{
size_t i;
size_t i, tries = 0;
if (sig != SIGTERM) return;
log_message (LOG_INFO,
"trying to bring down %zu threads...",
sblist_getsize(childs)
);
again:
for (i = 0; i < sblist_getsize(childs); i++) {
struct child *c = *((struct child**)sblist_get(childs, i));
if (!c->done) {
/* interrupt blocking operations.
this should cause the threads to shutdown orderly. */
close(c->conn.client_fd);
}
if (!c->done) pthread_kill(c->thread, SIGCHLD);
}
usleep(16);
usleep(8192);
collect_threads();
if (sblist_getsize(childs) != 0)
if(tries++ < 8) goto again;
if (sblist_getsize(childs) != 0)
log_message (LOG_CRIT,
"child_kill_children: %zu threads still alive!",