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

fix(server): Fix connection bug #695

Merged
merged 1 commit into from
Jan 16, 2023
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
18 changes: 11 additions & 7 deletions src/facade/dragonfly_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,18 @@ struct Connection::Request {
using MonitorMessage = std::string;

struct PipelineMsg {
absl::InlinedVector<MutableSlice, 6> 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<char, kReqStorageSize, mi_stl_allocator<char>>;

StorageType storage;

PipelineMsg(size_t nargs, size_t capacity) : args(nargs), storage(capacity) {
}

void Reset(size_t nargs, size_t capacity);

absl::InlinedVector<MutableSlice, 6> args;
StorageType storage;
};

static constexpr size_t kSizeOfPipelineMsg = sizeof(PipelineMsg);
Expand Down Expand Up @@ -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<PipelineMsg>(&payload);
if (msg) {
if (msg->storage.size() < capacity) {
msg->storage.resize(capacity);
}
Comment on lines -210 to -212
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I replaced it with just resize, because resizing to a smaller values doesn't actually shrink the storage to fit. The tail range is trivially destructible, so it should be no difference?

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) {
Expand Down