mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-06-20 01:17:49 +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:
@@ -248,7 +248,6 @@ httpClientRequest(
|
|||||||
|
|
||||||
MEM_CONTEXT_TEMP_BEGIN()
|
MEM_CONTEXT_TEMP_BEGIN()
|
||||||
{
|
{
|
||||||
bool complete = false;
|
|
||||||
bool retry;
|
bool retry;
|
||||||
Wait *wait = waitNew(this->timeout);
|
Wait *wait = waitNew(this->timeout);
|
||||||
|
|
||||||
@@ -451,12 +450,12 @@ httpClientRequest(
|
|||||||
// and choose errors in this class to retry.
|
// and choose errors in this class to retry.
|
||||||
if (httpClientResponseCode(this) / 100 == HTTP_RESPONSE_CODE_RETRY_CLASS)
|
if (httpClientResponseCode(this) / 100 == HTTP_RESPONSE_CODE_RETRY_CLASS)
|
||||||
THROW_FMT(ServiceError, "[%u] %s", httpClientResponseCode(this), strPtr(httpClientResponseMessage(this)));
|
THROW_FMT(ServiceError, "[%u] %s", httpClientResponseCode(this), strPtr(httpClientResponseMessage(this)));
|
||||||
|
|
||||||
// Request was successful
|
|
||||||
complete = true;
|
|
||||||
}
|
}
|
||||||
CATCH_ANY()
|
CATCH_ANY()
|
||||||
{
|
{
|
||||||
|
tlsSessionFree(this->tlsSession);
|
||||||
|
this->tlsSession = NULL;
|
||||||
|
|
||||||
// Retry if wait time has not expired
|
// Retry if wait time has not expired
|
||||||
if (waitMore(wait))
|
if (waitMore(wait))
|
||||||
{
|
{
|
||||||
@@ -465,16 +464,12 @@ httpClientRequest(
|
|||||||
|
|
||||||
httpClientStatLocal.retry++;
|
httpClientStatLocal.retry++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
tlsSessionFree(this->tlsSession);
|
RETHROW();
|
||||||
this->tlsSession = NULL;
|
|
||||||
}
|
}
|
||||||
TRY_END();
|
TRY_END();
|
||||||
}
|
}
|
||||||
while (!complete && retry);
|
while (retry);
|
||||||
|
|
||||||
if (!complete)
|
|
||||||
RETHROW();
|
|
||||||
|
|
||||||
// Move the result buffer (if any) to the parent context
|
// Move the result buffer (if any) to the parent context
|
||||||
bufMove(result, memContextPrior());
|
bufMove(result, memContextPrior());
|
||||||
|
|||||||
@@ -85,7 +85,6 @@ sckClientOpen(SocketClient *this)
|
|||||||
|
|
||||||
MEM_CONTEXT_TEMP_BEGIN()
|
MEM_CONTEXT_TEMP_BEGIN()
|
||||||
{
|
{
|
||||||
bool connected = false;
|
|
||||||
bool retry;
|
bool retry;
|
||||||
Wait *wait = waitNew(this->timeout);
|
Wait *wait = waitNew(this->timeout);
|
||||||
|
|
||||||
@@ -141,9 +140,6 @@ sckClientOpen(SocketClient *this)
|
|||||||
result = sckSessionNew(sckSessionTypeClient, fd, this->host, this->port, this->timeout);
|
result = sckSessionNew(sckSessionTypeClient, fd, this->host, this->port, this->timeout);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_PRIOR_END();
|
MEM_CONTEXT_PRIOR_END();
|
||||||
|
|
||||||
// Connection was successful
|
|
||||||
connected = true;
|
|
||||||
}
|
}
|
||||||
CATCH_ANY()
|
CATCH_ANY()
|
||||||
{
|
{
|
||||||
@@ -158,13 +154,12 @@ sckClientOpen(SocketClient *this)
|
|||||||
|
|
||||||
sckClientStatLocal.retry++;
|
sckClientStatLocal.retry++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
RETHROW();
|
||||||
}
|
}
|
||||||
TRY_END();
|
TRY_END();
|
||||||
}
|
}
|
||||||
while (!connected && retry);
|
while (retry);
|
||||||
|
|
||||||
if (!connected)
|
|
||||||
RETHROW();
|
|
||||||
|
|
||||||
sckClientStatLocal.session++;
|
sckClientStatLocal.session++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -271,7 +271,6 @@ tlsClientOpen(TlsClient *this)
|
|||||||
|
|
||||||
MEM_CONTEXT_TEMP_BEGIN()
|
MEM_CONTEXT_TEMP_BEGIN()
|
||||||
{
|
{
|
||||||
bool connected = false;
|
|
||||||
bool retry;
|
bool retry;
|
||||||
Wait *wait = waitNew(this->timeout);
|
Wait *wait = waitNew(this->timeout);
|
||||||
|
|
||||||
@@ -292,9 +291,6 @@ tlsClientOpen(TlsClient *this)
|
|||||||
|
|
||||||
// Create the TLS session
|
// Create the TLS session
|
||||||
result = tlsSessionNew(session, sckClientOpen(this->socketClient), this->timeout);
|
result = tlsSessionNew(session, sckClientOpen(this->socketClient), this->timeout);
|
||||||
|
|
||||||
// Connection was successful
|
|
||||||
connected = true;
|
|
||||||
}
|
}
|
||||||
CATCH_ANY()
|
CATCH_ANY()
|
||||||
{
|
{
|
||||||
@@ -309,13 +305,12 @@ tlsClientOpen(TlsClient *this)
|
|||||||
|
|
||||||
tlsClientStatLocal.retry++;
|
tlsClientStatLocal.retry++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
RETHROW();
|
||||||
}
|
}
|
||||||
TRY_END();
|
TRY_END();
|
||||||
}
|
}
|
||||||
while (!connected && retry);
|
while (retry);
|
||||||
|
|
||||||
if (!connected)
|
|
||||||
RETHROW();
|
|
||||||
|
|
||||||
tlsSessionMove(result, memContextPrior());
|
tlsSessionMove(result, memContextPrior());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user