Skip to content

Continuation activation race condition fix #342

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

Merged
merged 4 commits into from
Oct 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions eventstream_rpc/source/EventStreamClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,15 @@ namespace Aws
int errorCode =
EventStreamCppToNativeCrtBuilder::s_fillNativeHeadersArray(headers, &headersArray, m_allocator);

/*
* Regardless of how the promise gets moved around (or not), this future should stay valid as a return
* value.
*
* We pull it out early because the call to aws_event_stream_rpc_client_continuation_activate() may complete
* and delete the promise before we pull out the future afterwords.
*/
std::future<RpcError> retValue = onFlushPromise.get_future();

if (!errorCode)
{
struct aws_event_stream_rpc_message_args msg_args;
Expand Down Expand Up @@ -1001,12 +1010,8 @@ namespace Aws
onFlushPromise.set_value({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
Crt::Delete(callbackContainer, m_allocator);
}
else
{
return callbackContainer->onFlushPromise.get_future();
}

return onFlushPromise.get_future();
return retValue;
}

std::future<RpcError> ClientContinuation::SendMessage(
Expand Down Expand Up @@ -1588,4 +1593,4 @@ namespace Aws
}

} /* namespace Eventstreamrpc */
} // namespace Aws
} // namespace Aws