Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy bi-directional event stream request #3311

Merged
merged 2 commits into from
Feb 25, 2025

Conversation

SergeyRyabinin
Copy link
Contributor

@SergeyRyabinin SergeyRyabinin commented Feb 24, 2025

Issue #, if available:
Undefined behavior:

  • on request copying;
  • undefined behavior if the lifetime of the request is not maintained by user

Description of changes:
Create a request copy for async execution.
Avoid capturing objects by raw pointers into lambdas factories to avoid dangling pointers/reference.

Check all that applies:

  • Did a review by yourself.
  • Added proper tests to cover this PR. (If tests are not applicable, explain.)
  • Checked if this PR is a breaking (APIs have been changed) change.
  • Checked if this PR will not introduce cross-platform inconsistent behavior.
  • Checked if this PR would require a ReadMe/Wiki update.

Check which platforms you have built SDK on to verify the correctness of this PR.

  • Linux
  • Windows
  • Android
  • MacOS
  • IOS
  • Other Platforms

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@SergeyRyabinin SergeyRyabinin force-pushed the sr/bidirectEventStreamCopyRq branch 2 times, most recently from cad86c2 to f6975df Compare February 24, 2025 18:47
@@ -305,7 +305,8 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri,
coreMetrics.httpClientMetrics = httpRequest->GetRequestMetrics();
TracingUtils::EmitCoreHttpMetrics(httpRequest->GetRequestMetrics(),
*m_telemetryProvider->getMeter(this->GetServiceClientName(), {}),
{{TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName()},{TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName()}});
{{TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName()},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it crashes again we will know if service client or request is in UB.

@@ -53,6 +53,7 @@ namespace Aws

void EventStreamDecoder::ResetEventStreamHandler(EventStreamHandler* handler)
{
m_eventStreamHandler = handler;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was a big one.

@@ -137,7 +137,7 @@ namespace Model
/**
* Underlying Event Stream Handler which is used to define callback functions.
*/
inline const ${operation.name}Handler& GetEventStreamHandler() const { return m_handler; }
inline ${operation.name}Handler& GetEventStreamHandler() { return m_handler; }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returning object with only non-const methods by const reference is quite meaningless otherwise.

@SergeyRyabinin SergeyRyabinin force-pushed the sr/bidirectEventStreamCopyRq branch 2 times, most recently from 607e0fe to 602782b Compare February 24, 2025 19:42
@@ -9,6 +9,7 @@
#include <aws/core/utils/logging/ErrorMacros.h>
#include <aws/core/utils/component-registry/ComponentRegistry.h>


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not changes in file

AWS_LOGSTREAM_FATAL(ClientT::GetAllocationTag(),
"Unexpected nullptr bi-directional streaming request on response streaming factory call!");
assert(false);
return nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of nullptr should we return a empty string stream? even though we have entered a invalid state, a empty stream might help someone more gracefully exit than a null ptr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResponseStream is already handling nullptr condition in the c-tor.

ResponseStream::ResponseStream(Aws::IOStream* underlyingStreamToManage) :
m_underlyingStream(underlyingStreamToManage)
{
RegisterStream();
}

if (!request) {
AWS_LOGSTREAM_FATAL(ClientT::GetAllocationTag(), "Unexpected nullptr bi-directional streaming request on initial response!");
assert(false);
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit i prefer no returns on a void function and to rely on if - else behavior i.e.

if (!request) {
  ....
} else if (!response) {
  ....
} else {
  .....
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with ptr check macros.

m_stream(stream),
m_method(method),
m_signerName(signerName),
m_sem(Aws::MakeShared<Aws::Utils::Threading::Semaphore>("BidirectionalEventStreamingTask", 0, 1)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we want to use a semaphore and not a mutex if max value of semaphore is 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the original generated design code.
We could switch to a singal, but it will take 2 more member variables (mutex and a conditional_variable) to pass around instead of this single one.

};
for (size_t i = 0; i < 2; ++i) {
client->StartStreamTranscriptionAsync(request, OnStreamReady, OnResponseCallback, nullptr /*context*/);
semaphore.WaitOne();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a reasonable "drop dead" timeout so that we can avoid locking unit tests if something goes wrong

@SergeyRyabinin SergeyRyabinin force-pushed the sr/bidirectEventStreamCopyRq branch 2 times, most recently from 9755fd5 to 54ca419 Compare February 24, 2025 21:07
@SergeyRyabinin SergeyRyabinin force-pushed the sr/bidirectEventStreamCopyRq branch 2 times, most recently from 0ee6fc5 to 2b6fdfb Compare February 25, 2025 08:34
@SergeyRyabinin SergeyRyabinin force-pushed the sr/bidirectEventStreamCopyRq branch from 2b6fdfb to aaaef77 Compare February 25, 2025 08:39
@SergeyRyabinin SergeyRyabinin merged commit 50f3795 into main Feb 25, 2025
3 of 4 checks passed
@SergeyRyabinin SergeyRyabinin deleted the sr/bidirectEventStreamCopyRq branch February 25, 2025 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants