From c670008d9894f16c45f89eeb8970ae1689418e24 Mon Sep 17 00:00:00 2001 From: Susan Hinrichs Date: Wed, 5 May 2021 21:27:27 +0000 Subject: [PATCH] Fix MLoc assert caused by s3auth --- plugins/s3_auth/s3_auth.cc | 54 ++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/plugins/s3_auth/s3_auth.cc b/plugins/s3_auth/s3_auth.cc index 5b381ab395f..d8d82449a56 100644 --- a/plugins/s3_auth/s3_auth.cc +++ b/plugins/s3_auth/s3_auth.cc @@ -991,36 +991,40 @@ S3Request::authorizeV2(S3Config *s3) int event_handler(TSCont cont, TSEvent event, void *edata) { - TSHttpTxn txnp = static_cast(edata); - S3Config *s3 = static_cast(TSContDataGet(cont)); - - S3Request request(txnp); - TSHttpStatus status = TS_HTTP_STATUS_INTERNAL_SERVER_ERROR; + TSHttpTxn txnp = static_cast(edata); + S3Config *s3 = static_cast(TSContDataGet(cont)); TSEvent enable_event = TS_EVENT_HTTP_CONTINUE; - switch (event) { - case TS_EVENT_HTTP_SEND_REQUEST_HDR: - if (request.initialize()) { - while (s3->reload_waiting) { - std::this_thread::yield(); - } + { + S3Request request(txnp); + TSHttpStatus status = TS_HTTP_STATUS_INTERNAL_SERVER_ERROR; - std::shared_lock lock(s3->reload_mutex); - status = request.authorize(s3); - } + switch (event) { + case TS_EVENT_HTTP_SEND_REQUEST_HDR: + if (request.initialize()) { + while (s3->reload_waiting) { + std::this_thread::yield(); + } - if (TS_HTTP_STATUS_OK == status) { - TSDebug(PLUGIN_NAME, "Successfully signed the AWS S3 URL"); - } else { - TSDebug(PLUGIN_NAME, "Failed to sign the AWS S3 URL, status = %d", status); - TSHttpTxnStatusSet(txnp, status); - enable_event = TS_EVENT_HTTP_ERROR; + std::shared_lock lock(s3->reload_mutex); + status = request.authorize(s3); + } + + if (TS_HTTP_STATUS_OK == status) { + TSDebug(PLUGIN_NAME, "Successfully signed the AWS S3 URL"); + } else { + TSDebug(PLUGIN_NAME, "Failed to sign the AWS S3 URL, status = %d", status); + TSHttpTxnStatusSet(txnp, status); + enable_event = TS_EVENT_HTTP_ERROR; + } + break; + default: + TSError("[%s] Unknown event for this plugin", PLUGIN_NAME); + TSDebug(PLUGIN_NAME, "unknown event for this plugin"); + break; } - break; - default: - TSError("[%s] Unknown event for this plugin", PLUGIN_NAME); - TSDebug(PLUGIN_NAME, "unknown event for this plugin"); - break; + // Most get S3Request out of scope in case the later plugins invalidate the TSAPI + // objects it references. Some cases were causing asserts from the destructor } TSHttpTxnReenable(txnp, enable_event);