From 1f7f0a111f7edd7b94dcfb870d644b0f9fbb90df Mon Sep 17 00:00:00 2001 From: Laurentiu Cristofor Date: Thu, 11 Feb 2021 15:04:33 -0800 Subject: [PATCH] Fix fds leaking after log truncation (#540) Co-authored-by: Laurentiu Cristofor --- production/db/core/src/db_client.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/production/db/core/src/db_client.cpp b/production/db/core/src/db_client.cpp index af04464be268..368db3ed984f 100644 --- a/production/db/core/src/db_client.cpp +++ b/production/db/core/src/db_client.cpp @@ -587,6 +587,11 @@ void client::rollback_transaction() size_t log_size; s_log.truncate_seal_and_close(fd_log, log_size); + // We now own destruction of fd_log. + auto cleanup_fd_log = make_scope_guard([&]() { + close_fd(fd_log); + }); + // Avoid sending transaction log fd to the server read only transactions. if (log_size > 0) { @@ -623,6 +628,11 @@ void client::commit_transaction() size_t log_size; s_log.truncate_seal_and_close(fd_log, log_size); + // We now own destruction of fd_log. + auto cleanup_fd_log = make_scope_guard([&]() { + close_fd(fd_log); + }); + // Send the server the commit event with the log segment fd. FlatBufferBuilder builder; build_client_request(builder, session_event_t::COMMIT_TXN);