Skip to content

Commit 9cb5ef6

Browse files
committed
Bug#37385923 routertest_integration_routing_sharing select_overlong times out
$ routertest_integration_routing_sharing --gtest_filter=Spec/ShareConnectionTest.select_overlong/ssl_modes_PREFERRED__DISABLED_socket takes over 150s to complete if Router is built with -DCMAKE_BUILD_TYPE=Debug. With RelWithDebInfo and Release the test takes 0.2s. Background ========== Building with CMAKE_BUILD_TYPE=Debug disables optimizations which leads to std::vector.resize() trying to initialize every byte before each read from an encrypted socket. For "select_overlong", 16Mbyte of memory are allocated, passed to SSL_read() which only uses 16kByte, but all 16M were tried to be initialized. Change ====== - before SSL_read() only resize() the std::vector by 16k, the max size SSL_read() will return. That reduces the test runtime from 150sec to 2sec. Change-Id: I5b60712ca01ec84fcc33b23a7ab82864af7a6e65
1 parent 742e16a commit 9cb5ef6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

router/src/routing/src/channel.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,18 @@ stdx::expected<size_t, std::error_code> Channel::read_to_plain(size_t sz) {
235235
size_t bytes_read{};
236236
// decrypt from src-ssl into the ssl-plain-buf
237237
while (sz > 0) {
238+
// read at most a SSL frame (16k) to avoid excessive resizes.
239+
//
240+
// | Debug | RelWithDebInfo
241+
// 1k | 2100ms | 256ms
242+
// 16k | 1966ms | 219ms
243+
// 256k | *6509ms* | 189ms
244+
const size_t to_read = std::min(sz, 16UL * 1024);
245+
238246
auto dyn_buf = net::dynamic_buffer(plain_buf);
239247

240248
// append to the plain buffer
241-
const auto read_res = read(dyn_buf, sz);
249+
const auto read_res = read(dyn_buf, to_read);
242250

243251
// sync the plain-view as the read() may have resized it.
244252
view_sync_plain();
@@ -248,7 +256,6 @@ stdx::expected<size_t, std::error_code> Channel::read_to_plain(size_t sz) {
248256

249257
sz -= transferred;
250258
bytes_read += transferred;
251-
252259
} else {
253260
// read from client failed.
254261

0 commit comments

Comments
 (0)