<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 4, 2017 at 11:39 AM, Tatsuo Ishii <span dir="ltr">&lt;<a href="mailto:ishii@sraoss.co.jp" target="_blank">ishii@sraoss.co.jp</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">&gt; Hi ishii-San<br>
&gt;<br>
&gt; I am looking into the issue<br>
&gt; <a href="http://www.pgpool.net/mantisbt/view.php?id=249" rel="noreferrer" target="_blank">http://www.pgpool.net/<wbr>mantisbt/view.php?id=249</a>, where<br>
&gt; pgpool-II sometimes does not de-escalations while shutting down. And as per<br>
&gt; the bug report, the issue starts to appear after this commit.<br>
&gt;<br>
&gt; Although I am not able to replicate the exact reported issue but It seems<br>
&gt; like the changes made by this commit can leave the zombie processes.<br>
&gt;<br>
&gt; As we are replacing the wait(NULL) with waitpid(,..WNOHANG)<br>
&gt;<br>
&gt; @@ -1365,8 +1367,10 @@ static RETSIGTYPE exit_handler(int sig)<br>
&gt;         POOL_SETMASK(&amp;UnBlockSig);<br>
&gt;      do<br>
&gt;      {<br>
&gt; -        wpid = wait(NULL);<br>
&gt; -    }while (wpid &gt; 0 || (wpid == -1 &amp;&amp; errno == EINTR));<br>
&gt; +               int ret_pid;<br>
&gt; +        wpid = waitpid(-1, &amp;ret_pid, WNOHANG);<br>
&gt; +    } while (wpid &gt; 0 || (wpid == -1 &amp;&amp; errno == EINTR));<br>
&gt;<br>
&gt; The problem with this logic is that after replacing the wait(NULL) with<br>
&gt; waitpid(,..WNOHANG) we can move forward without waiting for all child<br>
&gt; process to finish, especially if some child process takes a little longer<br>
&gt; to finish. Since waitpid() returns 0 indicating that there is no<br>
&gt; exiting process at the moment, even when the child processes exists.<br>
&gt; For example,<br>
&gt; at the time of system shutdown, the watchdog process sometimes takes few<br>
&gt; seconds to execute the de-escalation process before exiting, and meanwhile<br>
&gt; in the main process as soon as waitpid( WNOHANG) would return 0 and the<br>
&gt; pgpool-II main process exits itself leaving the watchdog process as a<br>
&gt; zombie.<br>
<br>
</div></div>You are right. I should have not used WNOHANG here. The line should<br>
have been:<br>
<br>
        wpid = waitpid(-1, &amp;ret_pid, 0);<br></blockquote><div><br></div><div>Thanks for the confirmation. I have committed this change. </div><div><br></div><div>Regards</div><div>Muhammad Usama</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class=""><br>
&gt; Also, is it possible if you can share the scenario where you ran into the<br>
&gt; infinite wait situation, as there may be some other issue in the code since<br>
&gt; as per the wait() system call documentation it returns -1 when there is no<br>
&gt; child process, so theoretically wait() call should not cause the infinite<br>
&gt; wait.<br>
<br>
</span>Not remember clearly but it maybe the case When a child receives a<br>
stop signal (SIGSTOP).<br>
<div class="HOEnZb"><div class="h5"><br>
&gt; On Thu, Jul 7, 2016 at 11:55 AM, Tatsuo Ishii &lt;<a href="mailto:ishii@postgresql.org">ishii@postgresql.org</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; Fix usage of wait(2) in pgpool main process<br>
&gt;&gt;<br>
&gt;&gt; Per [pgpool-hackers: 1444]. Here is the copy of the message:<br>
&gt;&gt;<br>
&gt;&gt; Hi Usama,<br>
&gt;&gt;<br>
&gt;&gt; I have noticed that the usage of wait(2) in pgpool main could cause<br>
&gt;&gt; infinite wait in the system call.<br>
&gt;&gt;<br>
&gt;&gt;     /* wait for all children to exit */<br>
&gt;&gt;     do<br>
&gt;&gt;     {<br>
&gt;&gt;         wpid = wait(NULL);<br>
&gt;&gt;     }while (wpid &gt; 0 || (wpid == -1 &amp;&amp; errno == EINTR));<br>
&gt;&gt;<br>
&gt;&gt; When child process dies, SIGCHLD signal is raised and wait(2) knows<br>
&gt;&gt; the event. However, multiple child death does not necessarily creates<br>
&gt;&gt; exact same number of SIGCHLD signal as the number of dead children and<br>
&gt;&gt; wait(2) could wait for an event which never happens in this case. I<br>
&gt;&gt; actually encountered this situation while testing pgpool-II. Solution<br>
&gt;&gt; is, to use waitpid(2) instead of wait(2).<br>
&gt;&gt;<br>
&gt;&gt; Branch<br>
&gt;&gt; ------<br>
&gt;&gt; master<br>
&gt;&gt;<br>
&gt;&gt; Details<br>
&gt;&gt; -------<br>
&gt;&gt; <a href="http://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=" rel="noreferrer" target="_blank">http://git.postgresql.org/<wbr>gitweb?p=pgpool2.git;a=<wbr>commitdiff;h=</a><br>
&gt;&gt; 0d1cdf96feb77de6f1dfc2d46ecd74<wbr>67325d1f79<br>
&gt;&gt;<br>
&gt;&gt; Modified Files<br>
&gt;&gt; --------------<br>
&gt;&gt; src/main/pgpool_main.c | 12 ++++++++----<br>
&gt;&gt; 1 file changed, 8 insertions(+), 4 deletions(-)<br>
&gt;&gt;<br>
&gt;&gt; ______________________________<wbr>_________________<br>
&gt;&gt; pgpool-committers mailing list<br>
&gt;&gt; <a href="mailto:pgpool-committers@pgpool.net">pgpool-committers@pgpool.net</a><br>
&gt;&gt; <a href="http://www.pgpool.net/mailman/listinfo/pgpool-committers" rel="noreferrer" target="_blank">http://www.pgpool.net/mailman/<wbr>listinfo/pgpool-committers</a><br>
&gt;&gt;<br>
</div></div></blockquote></div><br></div></div>