mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-24 06:53:59 +08:00
Revert to blocking connection establishment
Non-blocking connection establishment when connecting to data nodes caused flakiness for Windows/Appveyor tests. Revert to blocking for now until these issues can be investigated more thoroughly.
This commit is contained in:
parent
eede24bcf2
commit
b21d8631dc
@ -1207,81 +1207,7 @@ remote_connection_open_with_options_nothrow(const char *node_name, List *connect
|
|||||||
keywords[option_pos] = values[option_pos] = NULL;
|
keywords[option_pos] = values[option_pos] = NULL;
|
||||||
Assert(option_pos <= option_count);
|
Assert(option_pos <= option_count);
|
||||||
|
|
||||||
/* Try to establish a connection to a database while handling
|
pg_conn = PQconnectdbParams(keywords, values, 0 /* Do not expand dbname param */);
|
||||||
* interrupts. The connection attempt should be aborted if the user
|
|
||||||
* cancels the transaction (e.g., ctrl-c), so we need to use wait events
|
|
||||||
* and poll the socket and latch. Wrap in a try-catch since
|
|
||||||
* CHECK_FOR_INTERRUPTS() will throw an error and we need to clean up the
|
|
||||||
* connection in that case. */
|
|
||||||
PG_TRY();
|
|
||||||
{
|
|
||||||
/* According to libpq docs, one should check if the socket is
|
|
||||||
* writeable in the first iteration of the loop, before calling
|
|
||||||
* PQconnectPoll(). */
|
|
||||||
PostgresPollingStatusType pollstatus = PGRES_POLLING_WRITING;
|
|
||||||
bool stop_waiting = false;
|
|
||||||
|
|
||||||
pg_conn = PQconnectStartParams(keywords, values, 0 /* do not expand DB names */);
|
|
||||||
|
|
||||||
if (PQstatus(pg_conn) == CONNECTION_BAD)
|
|
||||||
{
|
|
||||||
finish_connection(pg_conn, errmsg);
|
|
||||||
pg_conn = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (NULL != pg_conn)
|
|
||||||
{
|
|
||||||
int events = WL_LATCH_SET;
|
|
||||||
|
|
||||||
#if PG12_GE
|
|
||||||
events |= WL_EXIT_ON_PM_DEATH;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (pollstatus)
|
|
||||||
{
|
|
||||||
case PGRES_POLLING_FAILED:
|
|
||||||
/* connection attempt failed */
|
|
||||||
stop_waiting = true;
|
|
||||||
finish_connection(pg_conn, errmsg);
|
|
||||||
pg_conn = NULL;
|
|
||||||
break;
|
|
||||||
case PGRES_POLLING_OK:
|
|
||||||
/* Connection attempt succeeded */
|
|
||||||
stop_waiting = true;
|
|
||||||
break;
|
|
||||||
case PGRES_POLLING_READING:
|
|
||||||
/* Should wait for read on socket */
|
|
||||||
events |= WL_SOCKET_READABLE;
|
|
||||||
break;
|
|
||||||
case PGRES_POLLING_WRITING:
|
|
||||||
/* Should wait for write on socket */
|
|
||||||
events |= WL_SOCKET_WRITEABLE;
|
|
||||||
break;
|
|
||||||
case PGRES_POLLING_ACTIVE:
|
|
||||||
Assert(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stop_waiting)
|
|
||||||
break;
|
|
||||||
|
|
||||||
WaitLatchOrSocket(MyLatch, events, PQsocket(pg_conn), -1L, PG_WAIT_EXTENSION);
|
|
||||||
|
|
||||||
ResetLatch(MyLatch);
|
|
||||||
|
|
||||||
CHECK_FOR_INTERRUPTS();
|
|
||||||
|
|
||||||
pollstatus = PQconnectPoll(pg_conn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PG_CATCH();
|
|
||||||
{
|
|
||||||
if (NULL != pg_conn)
|
|
||||||
finish_connection(pg_conn, errmsg);
|
|
||||||
|
|
||||||
PG_RE_THROW();
|
|
||||||
}
|
|
||||||
PG_END_TRY();
|
|
||||||
|
|
||||||
/* Cast to (char **) to silence warning with MSVC compiler */
|
/* Cast to (char **) to silence warning with MSVC compiler */
|
||||||
pfree((char **) keywords);
|
pfree((char **) keywords);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user