[pgpool-general: 7756] problem connecting to backend

Martin Quevedo martin.quevedo at temiandu.com
Mon Oct 11 11:10:07 JST 2021


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?



                if (connect(fd, walk->ai_addr, walk->ai_addrlen) < 0)

                {

                        int errno2 = errno;

                        if (errno2 == EISCONN)

                        {

                                /* Socket is already connected */

                                break;

                        }



                        if ((errno2 == EINTR && retry) || errno2 == EAGAIN)

                                continue;



                        /*

                         * If error was "connect(2) is in progress", then
wait for

                         * completion.  Otherwise error out.

                         */



                        if ((errno2 != EINPROGRESS) && (errno2 != EALREADY))

                        {

                                ereport(LOG,

                                                (errmsg("failed to connect
to PostgreSQL server on 2 \"%s:%d\"", host, port),

                                                 errdetail("%m")));

                                return false;

                        }





Regards,

Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.pgpool.net/pipermail/pgpool-general/attachments/20211010/271dfbee/attachment.htm>


More information about the pgpool-general mailing list