From daf5473ce14d87550d53b7f66aa2af2958d76d4f Mon Sep 17 00:00:00 2001 From: Vladislav Date: Mon, 16 Jan 2023 19:53:48 +0300 Subject: [PATCH] fix(server): Fix connection bug (#695) --- src/facade/dragonfly_connection.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/facade/dragonfly_connection.cc b/src/facade/dragonfly_connection.cc index 073385b10330..d5dae41f1f07 100644 --- a/src/facade/dragonfly_connection.cc +++ b/src/facade/dragonfly_connection.cc @@ -111,17 +111,18 @@ struct Connection::Request { using MonitorMessage = std::string; struct PipelineMsg { - absl::InlinedVector args; - // I do not use mi_heap_t explicitly but mi_stl_allocator at the end does the same job // of using the thread's heap. // The capacity is chosen so that we allocate a fully utilized (256 bytes) block. using StorageType = absl::InlinedVector>; - StorageType storage; - PipelineMsg(size_t nargs, size_t capacity) : args(nargs), storage(capacity) { } + + void Reset(size_t nargs, size_t capacity); + + absl::InlinedVector args; + StorageType storage; }; static constexpr size_t kSizeOfPipelineMsg = sizeof(PipelineMsg); @@ -207,15 +208,18 @@ void Connection::RequestDeleter::operator()(Request* req) const { void Connection::Request::Emplace(const RespVec& args, size_t capacity) { PipelineMsg* msg = get_if(&payload); if (msg) { - if (msg->storage.size() < capacity) { - msg->storage.resize(capacity); - } + msg->Reset(args.size(), capacity); } else { payload = PipelineMsg{args.size(), capacity}; } SetArgs(args); } +void Connection::Request::PipelineMsg::Reset(size_t nargs, size_t capacity) { + storage.resize(capacity); + args.resize(nargs); +} + Connection::Connection(Protocol protocol, util::HttpListenerBase* http_listener, SSL_CTX* ctx, ServiceInterface* service) : io_buf_(kMinReadSize), http_listener_(http_listener), ctx_(ctx), service_(service) {