[pgpool-general: 7761] Re: problem connecting to backend

Martin Quevedo martin.quevedo at temiandu.com
Mon Oct 11 21:57:37 JST 2021


Dear Tatsuo,

*I have applied and tested your patch but i am still getting errno zero a
few lines after the connect*

*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*

*regards,*
*Martin*

El lun, 11 de oct. de 2021 a la(s) 01:27, Tatsuo Ishii (ishii at sraoss.co.jp)
escribió:

> Hi Martin,
>
> > Hello all,
> >
> >
> >
> > I was experiencing problems connecting to my PG backends
> >
> > I started debugging and I found, in
> *src/protocol/pool_connection_pool.c*,
> > the following
> >
> >
> >
> > In function *connect_with_timeout*, after *if (connect(fd, walk->ai_addr,
> > walk->ai_addrlen) < 0)*
> >
> > The errno variable was quickly set to zero
> >
> > I was getting the value *EINPROGRESS*, but by the time the following code
> > was executed,
> >
> >
> >
> > *if ((errno != EINPROGRESS) && (errno != EALREADY))*
> >
> > *                        {…}*
> >
> >
> >
> > *errno* was already zero
> >
> >
> >
> > So, I assigned *errno* to a *int error* variable and used that one
> instead
> > of *errno*, which solved the problem
> >
> >
> >
> > Any ideas why *errno* can change to zero between the connect() call and
> the *if
> > ((errno != EINPROGRESS) && (errno != EALREADY))* line?
>
> One possibility is an interruption by a signal. When a signal arrives
> to the pgpool process, a signal handler is called. If the signal
> handler resets errno inside, you will see the errno is set to 0.  I
> though all signal handlers save the errno before processing the code
> in the signal handler, but I found questionable signal handler:
>
> static RETSIGTYPE die(int sig) in src/protocol/child.c.
>
> saving errno is executed *after* POOL_SETMASK(&BlockSig) is
> called. POOL_SETMASK(&BlockSig) calls system calls inside, the errno
> could be set to 0. This is clealry wrong.  If my theory is correct,
> attached patch should fix the problem. Can you please try it out?
>
> >                 if (connect(fd, walk->ai_addr, walk->ai_addrlen) < 0)
> >
> >                 {
> >
> >                         int errno2 = errno;
> >
> >                         if (errno2 == EISCONN)
>
> Unfortunately this will not fix the problem because of possible window.
> What if errno is set before this?
>
> >                         int errno2 = errno;
> --
> Tatsuo Ishii
> SRA OSS, Inc. Japan
> English: http://www.sraoss.co.jp/index_en.php
> Japanese:http://www.sraoss.co.jp
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.pgpool.net/pipermail/pgpool-general/attachments/20211011/e93a8ed7/attachment-0001.htm>


More information about the pgpool-general mailing list