<div dir="ltr">Dear <span style="color:rgb(32,33,36);font-size:0.875rem;font-weight:bold;letter-spacing:0.2px;font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;white-space:nowrap">Tatsuo,</span><div><span style="color:rgb(32,33,36);font-size:0.875rem;font-weight:bold;letter-spacing:0.2px;font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;white-space:nowrap"><br></span></div><div><font color="#202124" face="Roboto, RobotoDraft, Helvetica, Arial, sans-serif"><span style="font-size:14px;letter-spacing:0.2px;white-space:nowrap"><b>I have applied and tested your patch but i am still getting errno zero a few lines after the connect</b></span></font></div><div><font color="#202124" face="Roboto, RobotoDraft, Helvetica, Arial, sans-serif"><span style="font-size:14px;letter-spacing:0.2px;white-space:nowrap"><b><br></b></span></font></div><div><font color="#202124" face="Roboto, RobotoDraft, Helvetica, Arial, sans-serif"><span style="font-size:14px;letter-spacing:0.2px;white-space:nowrap"><b>I also added a debug line in the die function and i can see it is not being called after the connect function, so I think die function is not the one causing errno to be zero</b></span></font></div><div><font color="#202124" face="Roboto, RobotoDraft, Helvetica, Arial, sans-serif"><span style="font-size:14px;letter-spacing:0.2px;white-space:nowrap"><b><br></b></span></font></div><div><font color="#202124" face="Roboto, RobotoDraft, Helvetica, Arial, sans-serif"><span style="font-size:14px;letter-spacing:0.2px;white-space:nowrap"><b>regards,</b></span></font></div><div><font color="#202124" face="Roboto, RobotoDraft, Helvetica, Arial, sans-serif"><span style="font-size:14px;letter-spacing:0.2px;white-space:nowrap"><b>Martin</b></span></font></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El lun, 11 de oct. de 2021 a la(s) 01:27, Tatsuo Ishii (<a href="mailto:ishii@sraoss.co.jp">ishii@sraoss.co.jp</a>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Martin,<br>
<br>
> Hello all,<br>
> <br>
> <br>
> <br>
> I was experiencing problems connecting to my PG backends<br>
> <br>
> I started debugging and I found, in *src/protocol/pool_connection_pool.c*,<br>
> the following<br>
> <br>
> <br>
> <br>
> In function *connect_with_timeout*, after *if (connect(fd, walk->ai_addr,<br>
> walk->ai_addrlen) < 0)*<br>
> <br>
> The errno variable was quickly set to zero<br>
> <br>
> I was getting the value *EINPROGRESS*, but by the time the following code<br>
> was executed,<br>
> <br>
> <br>
> <br>
> *if ((errno != EINPROGRESS) && (errno != EALREADY))*<br>
> <br>
> *                        {…}*<br>
> <br>
> <br>
> <br>
> *errno* was already zero<br>
> <br>
> <br>
> <br>
> So, I assigned *errno* to a *int error* variable and used that one instead<br>
> of *errno*, which solved the problem<br>
> <br>
> <br>
> <br>
> Any ideas why *errno* can change to zero between the connect() call and the *if<br>
> ((errno != EINPROGRESS) && (errno != EALREADY))* line?<br>
<br>
One possibility is an interruption by a signal. When a signal arrives<br>
to the pgpool process, a signal handler is called. If the signal<br>
handler resets errno inside, you will see the errno is set to 0.  I<br>
though all signal handlers save the errno before processing the code<br>
in the signal handler, but I found questionable signal handler:<br>
<br>
static RETSIGTYPE die(int sig) in src/protocol/child.c.<br>
<br>
saving errno is executed *after* POOL_SETMASK(&BlockSig) is<br>
called. POOL_SETMASK(&BlockSig) calls system calls inside, the errno<br>
could be set to 0. This is clealry wrong.  If my theory is correct,<br>
attached patch should fix the problem. Can you please try it out?<br>
<br>
>                 if (connect(fd, walk->ai_addr, walk->ai_addrlen) < 0)<br>
> <br>
>                 {<br>
> <br>
>                         int errno2 = errno;<br>
> <br>
>                         if (errno2 == EISCONN)<br>
<br>
Unfortunately this will not fix the problem because of possible window.<br>
What if errno is set before this?<br>
<br>
>                         int errno2 = errno;<br>
--<br>
Tatsuo Ishii<br>
SRA OSS, Inc. Japan<br>
English: <a href="http://www.sraoss.co.jp/index_en.php" rel="noreferrer" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
Japanese:<a href="http://www.sraoss.co.jp" rel="noreferrer" target="_blank">http://www.sraoss.co.jp</a><br>
</blockquote></div>