in Amazon.QLDB.Driver/driver/QldbDriverBase.cs [169:229]
private bool GetIsSessionDeadAndThrowIfNoRetry(
QldbTransactionException qte,
T currentSession,
int maxRetries,
int retryAttempt)
{
if (qte is RetriableException)
{
// Always retry on the first attempt if failure was caused by a stale session in the pool.
if (qte.InnerException is InvalidSessionException && retryAttempt == 1)
{
this.Logger.LogDebug("Initial session received from pool invalid. Retrying...");
return true;
}
// Normal retry logic.
if (retryAttempt > maxRetries)
{
if (qte.IsSessionAlive)
{
this.ReleaseSession(currentSession);
}
else
{
this.poolPermits.Release();
}
throw qte.InnerException;
}
this.Logger.LogInformation("A recoverable error has occurred. Attempting retry #{}.", retryAttempt);
this.Logger.LogDebug(
"Errored Transaction ID: {}. Error cause: {}",
qte.TransactionId,
qte.InnerException.ToString());
if (qte.IsSessionAlive)
{
this.Logger.LogDebug("Retrying with a different session...");
this.ReleaseSession(currentSession);
}
else
{
this.Logger.LogDebug("Replacing invalid session...");
}
return !qte.IsSessionAlive;
}
else
{
if (qte.IsSessionAlive)
{
this.ReleaseSession(currentSession);
}
else
{
this.poolPermits.Release();
}
throw qte.InnerException;
}
}