From 5934bf595a8fd097ff3eb4d35a858df95f67d605 Mon Sep 17 00:00:00 2001 From: Dominik Lohmann Date: Mon, 30 Aug 2021 12:02:30 +0200 Subject: [PATCH 1/2] Fix possible garbage in status command output This had a slight race condition: We captured a `string_view` to every component's type, and used that as a key in the status output. However, when small string optimization is used, the addition/removal of components caused the string views to be invalidated. This change makes it so the status handler copies the keys. --- changelog/unreleased/bug-fixes/1872--status-garbage-output.md | 2 ++ libvast/vast/system/status.hpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/bug-fixes/1872--status-garbage-output.md diff --git a/changelog/unreleased/bug-fixes/1872--status-garbage-output.md b/changelog/unreleased/bug-fixes/1872--status-garbage-output.md new file mode 100644 index 00000000000..76dd6afc49d --- /dev/null +++ b/changelog/unreleased/bug-fixes/1872--status-garbage-output.md @@ -0,0 +1,2 @@ +The status command no longer occasionally contains garbage keys when the VAST +server is under high load. diff --git a/libvast/vast/system/status.hpp b/libvast/vast/system/status.hpp index 3bb277a3e73..46b5b43b9d5 100644 --- a/libvast/vast/system/status.hpp +++ b/libvast/vast/system/status.hpp @@ -138,10 +138,10 @@ void collect_status( caf::settings& s, std::string_view key) { collect_status( rs, timeout, verbosity, responder, - [key, &s](caf::settings& response) { + [key = std::string{key}, &s](caf::settings& response) { put(s, std::string_view{key}, std::move(response)); }, - [self = rs->self, key, &s](const caf::error& err) { + [self = rs->self, key = std::string{key}, &s](const caf::error& err) { VAST_WARN("{} failed to retrieve status for the key {}: {}", *self, key, err); put(s, std::string_view{key}, fmt::to_string(err)); From 87189ca550fcfc1f7fa750612cc8185780f046bc Mon Sep 17 00:00:00 2001 From: Dominik Lohmann Date: Mon, 30 Aug 2021 13:33:39 +0200 Subject: [PATCH 2/2] Remove unnecessary cast to string_view --- libvast/vast/system/status.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libvast/vast/system/status.hpp b/libvast/vast/system/status.hpp index 46b5b43b9d5..a72348027aa 100644 --- a/libvast/vast/system/status.hpp +++ b/libvast/vast/system/status.hpp @@ -139,12 +139,12 @@ void collect_status( collect_status( rs, timeout, verbosity, responder, [key = std::string{key}, &s](caf::settings& response) { - put(s, std::string_view{key}, std::move(response)); + put(s, key, std::move(response)); }, [self = rs->self, key = std::string{key}, &s](const caf::error& err) { VAST_WARN("{} failed to retrieve status for the key {}: {}", *self, key, err); - put(s, std::string_view{key}, fmt::to_string(err)); + put(s, key, fmt::to_string(err)); }); }