1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Simplify retry handling in tls/http/socket clients.

Travis-CI arm64 was not happy with this pattern, perhaps because connected was being reset after a longjmp() even though it should have stayed with its originally initialized value of false. In any case, tlsClientOpen() ended up returning NULL on error rather than throwing an exception.

The new pattern seems simpler and passes all tests unmodified, so even though the error was only seen in TlsClient it makes sense to propagate to the other clients.
This commit is contained in:
David Steele 2020-05-06 15:00:34 -04:00
parent 8aede3353c
commit 10a5182d62
3 changed files with 12 additions and 27 deletions

View File

@ -248,7 +248,6 @@ httpClientRequest(
MEM_CONTEXT_TEMP_BEGIN()
{
bool complete = false;
bool retry;
Wait *wait = waitNew(this->timeout);
@ -451,12 +450,12 @@ httpClientRequest(
// and choose errors in this class to retry.
if (httpClientResponseCode(this) / 100 == HTTP_RESPONSE_CODE_RETRY_CLASS)
THROW_FMT(ServiceError, "[%u] %s", httpClientResponseCode(this), strPtr(httpClientResponseMessage(this)));
// Request was successful
complete = true;
}
CATCH_ANY()
{
tlsSessionFree(this->tlsSession);
this->tlsSession = NULL;
// Retry if wait time has not expired
if (waitMore(wait))
{
@ -465,16 +464,12 @@ httpClientRequest(
httpClientStatLocal.retry++;
}
tlsSessionFree(this->tlsSession);
this->tlsSession = NULL;
else
RETHROW();
}
TRY_END();
}
while (!complete && retry);
if (!complete)
RETHROW();
while (retry);
// Move the result buffer (if any) to the parent context
bufMove(result, memContextPrior());

View File

@ -85,7 +85,6 @@ sckClientOpen(SocketClient *this)
MEM_CONTEXT_TEMP_BEGIN()
{
bool connected = false;
bool retry;
Wait *wait = waitNew(this->timeout);
@ -141,9 +140,6 @@ sckClientOpen(SocketClient *this)
result = sckSessionNew(sckSessionTypeClient, fd, this->host, this->port, this->timeout);
}
MEM_CONTEXT_PRIOR_END();
// Connection was successful
connected = true;
}
CATCH_ANY()
{
@ -158,13 +154,12 @@ sckClientOpen(SocketClient *this)
sckClientStatLocal.retry++;
}
else
RETHROW();
}
TRY_END();
}
while (!connected && retry);
if (!connected)
RETHROW();
while (retry);
sckClientStatLocal.session++;
}

View File

@ -271,7 +271,6 @@ tlsClientOpen(TlsClient *this)
MEM_CONTEXT_TEMP_BEGIN()
{
bool connected = false;
bool retry;
Wait *wait = waitNew(this->timeout);
@ -292,9 +291,6 @@ tlsClientOpen(TlsClient *this)
// Create the TLS session
result = tlsSessionNew(session, sckClientOpen(this->socketClient), this->timeout);
// Connection was successful
connected = true;
}
CATCH_ANY()
{
@ -309,13 +305,12 @@ tlsClientOpen(TlsClient *this)
tlsClientStatLocal.retry++;
}
else
RETHROW();
}
TRY_END();
}
while (!connected && retry);
if (!connected)
RETHROW();
while (retry);
tlsSessionMove(result, memContextPrior());
}