diff --git a/test/integration/fake_upstream.cc b/test/integration/fake_upstream.cc index c942e387ce5d..e35bb07a1183 100644 --- a/test/integration/fake_upstream.cc +++ b/test/integration/fake_upstream.cc @@ -410,8 +410,10 @@ std::string FakeRawConnection::waitForData(uint64_t num_bytes) { } void FakeRawConnection::write(const std::string& data, bool end_stream) { + std::unique_lock lock(lock_); ASSERT_FALSE(disconnected_); connection_.dispatcher().post([data, end_stream, this]() -> void { + std::unique_lock lock(lock_); ASSERT_FALSE(disconnected_); Buffer::OwnedImpl to_write(data); connection_.write(to_write, end_stream); diff --git a/test/integration/fake_upstream.h b/test/integration/fake_upstream.h index f7af85e61574..d38b2df66522 100644 --- a/test/integration/fake_upstream.h +++ b/test/integration/fake_upstream.h @@ -197,7 +197,10 @@ class FakeConnectionBase : public Network::ConnectionCallbacks { connection_.dispatcher().post([this]() -> void { connection_.addConnectionCallbacks(*this); }); } void enableHalfClose(bool enabled); - bool connected() const { return !disconnected_; } + bool connected() const { + std::unique_lock lock(lock_); + return !disconnected_; + } protected: FakeConnectionBase(QueuedConnectionWrapperPtr connection_wrapper) @@ -205,7 +208,7 @@ class FakeConnectionBase : public Network::ConnectionCallbacks { connection_wrapper_(std::move(connection_wrapper)) {} Network::Connection& connection_; - std::mutex lock_; + mutable std::mutex lock_; std::condition_variable connection_event_; bool disconnected_{}; bool half_closed_{};