From 53ee007002b9c339a0002f192658ee7d95dff56e Mon Sep 17 00:00:00 2001
From: Matej Ferencevic <matej.ferencevic@memgraph.io>
Date: Thu, 12 Jul 2018 11:44:59 +0200
Subject: [PATCH] Fix large Bolt messages

Reviewers: ipaljak

Reviewed By: ipaljak

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1490
---
 src/communication/bolt/v1/session.hpp | 5 +++++
 tests/unit/bolt_common.hpp            | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/src/communication/bolt/v1/session.hpp b/src/communication/bolt/v1/session.hpp
index 34673897a..bd9e193e3 100644
--- a/src/communication/bolt/v1/session.hpp
+++ b/src/communication/bolt/v1/session.hpp
@@ -72,6 +72,11 @@ class Session {
    */
   void Execute() {
     if (UNLIKELY(!handshake_done_)) {
+      // Resize the input buffer to ensure that a whole chunk can fit into it.
+      // This can be done only once because the buffer holds its size.
+      input_stream_.Resize(WHOLE_CHUNK_SIZE);
+
+      // Receive the handshake.
       if (input_stream_.size() < HANDSHAKE_SIZE) {
         DLOG(WARNING) << fmt::format("Received partial handshake of size {}",
                                      input_stream_.size());
diff --git a/tests/unit/bolt_common.hpp b/tests/unit/bolt_common.hpp
index 47dd75b3a..099f5fc95 100644
--- a/tests/unit/bolt_common.hpp
+++ b/tests/unit/bolt_common.hpp
@@ -34,6 +34,8 @@ class TestInputStream {
     data_.erase(data_.begin(), data_.begin() + count);
   }
 
+  void Resize(size_t len) {}
+
  private:
   std::vector<uint8_t> data_;
 };