From 8ec371fd8e8ba621364ffbf8a051ab09d9c392fc Mon Sep 17 00:00:00 2001 From: Eduard Bagdasaryan Date: Mon, 13 Jul 2020 16:56:15 +0300 Subject: [PATCH] FwdState::advanceDestination(): do cleanup regardless of the old error --- src/FwdState.cc | 20 +++++++++++++++----- src/FwdState.h | 3 +++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/FwdState.cc b/src/FwdState.cc index 57be02b16b..15749ab475 100644 --- a/src/FwdState.cc +++ b/src/FwdState.cc @@ -466,29 +466,38 @@ FwdState::useDestinations() stopAndDestroy("tried all destinations"); } } - void FwdState::fail(ErrorState * errorState) +{ + cleanup(); + doFail(errorState); +} + +void +FwdState::doFail(ErrorState * errorState) { debugs(17, 3, err_type_str[errorState->type] << " \"" << Http::StatusCodeString(errorState->httpStatus) << "\"\n\t" << entry->url()); delete err; err = errorState; - const auto oldDestinationReceipt = destinationReceipt; destinationReceipt = nullptr; if (!errorState->request) errorState->request = request; +} +void +FwdState::cleanup() +{ if (err->type != ERR_ZERO_SIZE_OBJECT) return; if (pconnRace == racePossible) { debugs(17, 5, HERE << "pconn race happened"); pconnRace = raceHappened; - if (oldDestinationReceipt) - destinations->reinstatePath(oldDestinationReceipt); + if (destinationReceipt) + destinations->reinstatePath(destinationReceipt); } if (ConnStateData *pinned_connection = request->pinnedConnection()) { @@ -798,9 +807,10 @@ FwdState::advanceDestination(const char *stepDescription, const Comm::Connection } catch (...) { debugs (17, 2, "exception while trying to " << stepDescription << ": " << CurrentException); closePendingConnection(conn, "connection preparation exception"); + cleanup(); if (!err) { auto error = new ErrorState(ERR_GATEWAY_FAILURE, Http::scInternalServerError, request, al); - fail(error); + doFail(error); } retryOrBail(); } diff --git a/src/FwdState.h b/src/FwdState.h index d29460b050..f091caf6ba 100644 --- a/src/FwdState.h +++ b/src/FwdState.h @@ -171,6 +171,9 @@ private: void notifyConnOpener(); + void doFail(ErrorState *err); + void cleanup(); + public: StoreEntry *entry; HttpRequest *request; -- 2.47.3