From e4434feafc8bac3bee77b3d63c85cb47f33363e5 Mon Sep 17 00:00:00 2001 From: arm7star Date: Thu, 12 Sep 2024 10:57:19 +0800 Subject: [PATCH] test/crimson/test_messenger_thrash: fix local variable out of scope in async task test_messenger_thrash UT shows, ``` ==461141==ERROR: AddressSanitizer: stack-use-after-return on address 0xffffb0b37c20 at pc 0xaaaad7239508 bp 0xffffeb113c50 sp 0xffffeb113c48 READ of size 4 at 0xffffb0b37c20 thread T0 #0 0xaaaad7239504 in (anonymous namespace)::SyntheticWorkload::wait_for_done()::'lambda0'()::operator()() const /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/test/crimson/test_messenger_thrash.cc:455:13 #1 0xaaaad723a1c0 in seastar::internal::do_until_state<(anonymous namespace)::SyntheticWorkload::wait_for_done()::'lambda'(), (anonymous namespace)::SyntheticWorkload::wait_for_done()::'lambda0'()>::run_and_dispose() /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/seastar/include/seastar/core/loop.hh:303:26 #2 0xaaaadacfb790 in seastar::reactor::run_tasks(seastar::reactor::task_queue&) /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/seastar/src/core/reactor.cc:2653:14 #3 0xaaaadad04288 in seastar::reactor::run_some_tasks() /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/seastar/src/core/reactor.cc:3123:9 #4 0xaaaadad07cd0 in seastar::reactor::do_run() /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/seastar/src/core/reactor.cc:3291:9 #5 0xaaaadad05d60 in seastar::reactor::run() /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/seastar/src/core/reactor.cc:3181:16 #6 0xaaaadaa860d8 in seastar::app_template::run_deprecated(int, char**, std::function&&) /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/seastar/src/core/app-template.cc:276:31 #7 0xaaaadaa83fb0 in seastar::app_template::run(int, char**, std::function ()>&&) /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/seastar/src/core/app-template.cc:167:12 #8 0xaaaad7203d88 in main /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/test/crimson/test_messenger_thrash.cc:669:14 #9 0xffffb32773f8 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #10 0xffffb32774c8 in __libc_start_main csu/../csu/libc-start.c:392:3 #11 0xaaaad712546c in _start (/home/jenkins-build/build/workspace/ceph-pull-requests-arm64/build/bin/unittest-seastar-messenger-thrash+0x3b5546c) (BuildId: b0048d750e057d178816f94b3ce0459971785191) ``` Address 0xffffb0b37c20 is located in stack of thread T0 at offset 32 in frame #0 0xaaaad7493ed8 in ceph::buffer::v15_2_0::list::buffers_t::clear_and_dispose() /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/include/buffer.h:596 Signed-off-by: arm7star --- src/test/crimson/test_messenger_thrash.cc | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/test/crimson/test_messenger_thrash.cc b/src/test/crimson/test_messenger_thrash.cc index 4146ec45b6634..72e3f221755b2 100644 --- a/src/test/crimson/test_messenger_thrash.cc +++ b/src/test/crimson/test_messenger_thrash.cc @@ -447,15 +447,16 @@ class SyntheticWorkload { } seastar::future<> wait_for_done() { - int i = 0; - return seastar::do_until( - [this] { return !dispatcher.get_num_pending_msgs(); }, - [this, &i] - { - if (i++ % 50 == 0){ - print_internal_state(true); - } - return seastar::sleep(100ms); + return seastar::do_with(0, [this] (int &i) { + return seastar::do_until( + [this] { return !dispatcher.get_num_pending_msgs(); }, + [this, &i] { + if (i++ % 50 == 0) { + print_internal_state(true); + } + return seastar::sleep(100ms); + } + ); }).then([this] { return seastar::do_for_each(available_servers, [] (auto server) { if (verbose) {