lordgamez commented on code in PR #2094:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2094#discussion_r2799170800
##########
core-framework/src/http/HTTPStream.cpp:
##########
@@ -75,14 +73,12 @@ size_t HttpStream::write(const uint8_t* value, size_t size)
{
size_t HttpStream::read(std::span<std::byte> buf) {
if (buf.empty()) { return 0; }
if (!IsNullOrEmpty(buf)) {
- if (!started_) {
- std::lock_guard<std::mutex> lock(mutex_);
- if (!started_) {
- auto read_callback =
std::make_unique<HTTPReadByteOutputCallback>(66560, true);
- http_client_future_ = std::async(std::launch::async,
submit_read_client, http_client_, read_callback.get());
- http_client_->setReadCallback(std::move(read_callback));
- started_ = true;
- }
+ std::lock_guard<std::mutex> lock(mutex_);
+ if (!read_started_) {
+ auto read_callback = std::make_unique<HTTPReadByteOutputCallback>(66560,
true);
+ http_client_read_future_ = std::async(std::launch::async,
submit_read_client, http_client_, read_callback.get());
+ http_client_->setReadCallback(std::move(read_callback));
+ read_started_ = true;
}
return
gsl::not_null(getByteOutputReadCallback())->readFully(reinterpret_cast<char*>(buf.data()),
buf.size());
Review Comment:
Calling the callback read outside the lock would make it possible to replace
the callback from another thread while being read, so it should remain under
the mutex.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]