From 44f6a062fb13bf45d64d9a8c52e48ead6d52174e Mon Sep 17 00:00:00 2001 From: Bret Ambrose Date: Thu, 31 Oct 2024 15:33:03 -0700 Subject: [PATCH] PR updates --- source/iot/MqttRequestResponseClient.cpp | 15 +++++++++++++++ tests/MqttRequestResponse.cpp | 7 ++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/source/iot/MqttRequestResponseClient.cpp b/source/iot/MqttRequestResponseClient.cpp index b5205c706..2bdcb960f 100644 --- a/source/iot/MqttRequestResponseClient.cpp +++ b/source/iot/MqttRequestResponseClient.cpp @@ -18,6 +18,12 @@ namespace Aws namespace RequestResponse { + /* + * RAII wrapper around taking a read lock for a referenced read-write lock. + * + * Used to protect the stream from destruction while in a callback or Open() call. Protects the + * m_closed field of StreamingOperationImpl. + */ class StreamReadLock { public: @@ -29,6 +35,15 @@ namespace Aws struct aws_rw_lock *m_lock; }; + /* + * RAII wrapper around taking a *conditional* write lock for a referenced read-write lock. Protects the + * m_closed field of StreamingOperationImpl. + * + * Used to block callbacks while destruction is triggered. Only ever used by the stream destructor. + * We conditionally take the lock because if we're already in the event loop thread we're safe and we + * are probably (but not guaranteed to be) in a callback. This prevents deadlock from trying to upgrade + * an already taken read lock to a write lock, which is not supported by the underlying read-write lock. + */ class StreamWriteLock { public: diff --git a/tests/MqttRequestResponse.cpp b/tests/MqttRequestResponse.cpp index 5b8335c8b..f76208bdf 100644 --- a/tests/MqttRequestResponse.cpp +++ b/tests/MqttRequestResponse.cpp @@ -221,23 +221,24 @@ static TestContext s_CreateClient( Aws::Iot::RequestResponse::RequestResponseClientOptions *options = NULL) { TestContext context; + Aws::Iot::RequestResponse::RequestResponseClientOptions finalOptions; Aws::Iot::RequestResponse::RequestResponseClientOptions finalOptions; struct aws_string *host = NULL; struct aws_string *certificatePath = NULL; struct aws_string *privateKeyPath = NULL; - if (aws_get_environment_value(allocator, s_rrEnvVariableHost, &host)) + if (aws_get_environment_value(allocator, s_rrEnvVariableHost, &host) || !host) { goto done; } - if (aws_get_environment_value(allocator, s_rrEnvVariableCertificatePath, &certificatePath)) + if (aws_get_environment_value(allocator, s_rrEnvVariableCertificatePath, &certificatePath) || !certificatePath) { goto done; } - if (aws_get_environment_value(allocator, s_rrEnvVariablePrivateKeyPath, &privateKeyPath)) + if (aws_get_environment_value(allocator, s_rrEnvVariablePrivateKeyPath, &privateKeyPath) || !privateKeyPath) { goto done; }