libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] [PATCH] Avoid silent misbehaviour on pthread join fa


From: Christian Grothoff
Subject: Re: [libmicrohttpd] [PATCH] Avoid silent misbehaviour on pthread join failure
Date: Fri, 9 Oct 2009 15:24:48 +0200
User-agent: KMail/1.12.1 (Linux/2.6.28-grml64; KDE/4.3.1; x86_64; ; )

Makes sense.  I've fixed this in SVN HEAD, but with a slightly more verbose 
report in case that --enable-messages was given to configure.

Thanks!

Christian

On Friday 09 October 2009 13:23:40 Mike Crowe wrote:
> I've just spent a while investigating a problem that was causing
> pthread_join to fail. It was all of my own making but it took me a
> while to track down because libmicrohttpd just continued regardless
> and raced with the thread that it thought should be dead by that
> point. Most of the time this was benign but very rarely it would go
> bang.
> 
> Anyway, this patch means that libmicrohttpd should no longer continue
> regardless. I've tried to follow the style of the existing code.
> 
> Thanks.
> 
> Mike.
> 
> --- libmicrohttpd-0.4.2.orig/src/daemon/daemon.c      2009-04-02
>  02:47:04.000000000 +0100 +++
>  libmicrohttpd-0.4.2/src/daemon/daemon.c      2009-10-09 12:12:30.000000000
>  +0100 @@ -755,8 +755,10 @@ MHD_cleanup_connections (struct MHD_Daem
>              prev->next = pos->next;
>            if (0 != (pos->daemon->options & MHD_USE_THREAD_PER_CONNECTION))
>              {
> -              pthread_kill (pos->pid, SIGALRM);
> -              pthread_join (pos->pid, &unused);
> +              if (0 != pthread_kill (pos->pid, SIGALRM))
> +                abort();
> +              if (0 != pthread_join (pos->pid, &unused))
> +                abort();
>              }
>            MHD_destroy_response (pos->response);
>            MHD_pool_destroy (pos->pool);
> @@ -1442,7 +1444,8 @@ MHD_stop_daemon (struct MHD_Daemon *daem
>      pthread_kill (daemon->worker_pool[i].pid, SIGALRM);
>    for (i = 0; i < daemon->worker_pool_size; ++i)
>      {
> -      pthread_join (daemon->worker_pool[i].pid, &unused);
> +      if (0 != pthread_join (daemon->worker_pool[i].pid, &unused))
> +        abort();
>        MHD_close_connections (&daemon->worker_pool[i]);
>      }
>    free (daemon->worker_pool);
> @@ -1451,8 +1454,10 @@ MHD_stop_daemon (struct MHD_Daemon *daem
>        ((0 != (daemon->options & MHD_USE_SELECT_INTERNALLY))
>          && (0 == daemon->worker_pool_size)))
>      {
> -      pthread_kill (daemon->pid, SIGALRM);
> -      pthread_join (daemon->pid, &unused);
> +      if (0 != pthread_kill (daemon->pid, SIGALRM))
> +        abort();
> +      if (0 != pthread_join (daemon->pid, &unused))
> +        abort();
>      }
>    MHD_close_connections (daemon);
> 

-- 
http://grothoff.org/christian/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]