<div dir="ltr">quick question<div><br></div><div>for this part of your patch</div><div><br></div><div>@@ -189,7 +196,10 @@ pvsnprintf(char *buf, size_t len, const char *fmt, va_list args)<br>    }<br> <br>        if (len >= MaxAllocSize / 2)<br>+      {<br>+            errno = save_errno;<br>          return MaxAllocSize;<br>+ }<br> <br>        return len * 2;<br> }<br></div><div><br></div><div>wouldnt it be better to do it like this?</div><div><br></div><div>@@ -189,7 +196,10 @@ pvsnprintf(char *buf, size_t len, const char *fmt, va_list args)<br>  }<br><br></div><div>+ errno = save_errno; <br>  if (len >= MaxAllocSize / 2)<br>     return MaxAllocSize;<br> <br>    return len * 2;<br> }<br></div><div><br></div><div>in order to cover both returns ?</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El lun, 11 de oct. de 2021 a la(s) 21:42, 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">> Dear Tatsuo,<br>
> <br>
> I was able to narrow it down<br>
> errno = 0 in file src/utils/psprintf.c is causing my problem<br>
> <br>
> size_t<br>
> pvsnprintf(char *buf, size_t len, const char *fmt, va_list args)<br>
> {<br>
>         int                     nprinted;<br>
> <br>
>         Assert(len > 0);<br>
>         //errno = 0;<br>
> <br>
> Shouldn't you save errno in that function and restore it on return instead<br>
> of setting it to zero ?<br>
<br>
Good catch! You are absolutely right. Can you please review attached patch?<br>
<br>
> Regards,<br>
> Martin <br>
> <br>
> <br>
> <br>
> -----Original Message-----<br>
> From: Tatsuo Ishii <<a href="mailto:ishii@sraoss.co.jp" target="_blank">ishii@sraoss.co.jp</a>> <br>
> Sent: Monday, October 11, 2021 1:27 AM<br>
> To: <a href="mailto:martin.quevedo@temiandu.com" target="_blank">martin.quevedo@temiandu.com</a><br>
> Cc: <a href="mailto:pgpool-general@pgpool.net" target="_blank">pgpool-general@pgpool.net</a><br>
> Subject: Re: [pgpool-general: 7756] problem connecting to backend<br>
> <br>
> 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 <br>
>> *src/protocol/pool_connection_pool.c*,<br>
>> the following<br>
>> <br>
>> <br>
>> <br>
>> In function *connect_with_timeout*, after *if (connect(fd, <br>
>> 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 <br>
>> code 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 <br>
>> instead of *errno*, which solved the problem<br>
>> <br>
>> <br>
>> <br>
>> Any ideas why *errno* can change to zero between the connect() call <br>
>> and the *if ((errno != EINPROGRESS) && (errno != EALREADY))* line?<br>
> <br>
> One possibility is an interruption by a signal. When a signal arrives to the<br>
> pgpool process, a signal handler is called. If the signal handler resets<br>
> errno inside, you will see the errno is set to 0.  I though all signal<br>
> handlers save the errno before processing the code in the signal handler,<br>
> 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 called.<br>
> POOL_SETMASK(&BlockSig) calls system calls inside, the errno could be set to<br>
> 0. This is clealry wrong.  If my theory is correct, attached patch should<br>
> 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>
> <br>
</blockquote></div>