Skip to content

common/StackStringStream: Move destructed out of Cache - #68705

Closed
adamemerson wants to merge 1 commit into
ceph:mainfrom
adamemerson:wip-stackstream-post-destruct-access
Closed

adamemerson wants to merge 1 commit into
ceph:mainfrom
adamemerson:wip-stackstream-post-destruct-access

Conversation

@adamemerson

Copy link
Copy Markdown
Contributor

The thread local Cache contains a 'destructed' flag to warn users away from it. Accessing destructed objects is undefined behavior, and Clang has got aggressive about it.

To fix, replace cache.destructed with a thread local cache_destructed. Since bool is trivial it should last as long as the thread.

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

The thread local `Cache` contains a 'destructed' flag to warn users
away from it. Accessing destructed objects is undefined behavior, and
Clang has got aggressive about it.

To fix, replace `cache.destructed` with a thread local
`cache_destructed`. Since bool is trivial it should last as long as
the thread.

Signed-off-by: Adam C. Emerson <[email protected]>
@adamemerson
adamemerson requested a review from mkogan1 April 30, 2026 21:25
@mkogan1

mkogan1 commented May 3, 2026

Copy link
Copy Markdown
Contributor

@adamemerson, sorry, it still seg faulted:
image

Thread 112 "io_context_pool" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffc017b6c0 (LWP 271915)]
0x000000000807dff0 in ?? ()
Missing rpms, try: dnf --enablerepo='*debug*' install gperftools-libs-debuginfo-2.15-4.el10_0.x86_64 liboath-debuginfo-2.6.12-1.el10_0.x86_64 libicu-debuginfo-74.2-5.el10_0.x86_64 libcurl-debuginfo-8.12.1-2.el10.x86_64 expat-debuginfo-2.7.1-1.el10_0.3.x86_64 lmdb-libs-debuginfo-0.9.32-4.el10.x86_64 lua-libs-debuginfo-5.4.6-7.el10.x86_64 glibc-debuginfo-2.39-58.el10_1.2.x86_64 openssl-libs-debuginfo-3.5.1-5.el10_1.x86_64 librabbitmq-debuginfo-0.14.0-3.el10.x86_64 libcap-debuginfo-2.69-7.el10.x86_64 libblkid-debuginfo-2.40.2-13.el10.x86_64 systemd-libs-debuginfo-257-13.el10.rocky.0.1.x86_64 zlib-ng-compat-debuginfo-2.2.3-2.el10.x86_64 sqlite-libs-debuginfo-3.46.1-5.el10_1.x86_64 libstdc++-debuginfo-14.3.1-2.1.el10.x86_64 libgcc-debuginfo-14.3.1-2.1.el10.x86_64 libunwind-debuginfo-1.8.0-4.el10_0.x86_64 libnghttp2-debuginfo-1.64.0-2.el10.x86_64 libidn2-debuginfo-2.3.7-3.el10.x86_64 libssh-debuginfo-0.11.1-5.el10_1.x86_64 libpsl-debuginfo-0.21.5-6.el10.x86_64 krb5-libs-debuginfo-1.21.3-8.el10_0.x86_64 openldap-debuginfo-2.6.9-1.el10.x86_64 libbrotli-debuginfo-1.1.0-7.el10_1.x86_64 libunistring-debuginfo-1.1-10.el10.x86_64 libcom_err-debuginfo-1.47.1-4.el10.x86_64 keyutils-libs-debuginfo-1.6.3-5.el10.x86_64 libevent-debuginfo-2.1.12-16.el10.x86_64 cyrus-sasl-lib-debuginfo-2.1.28-29.el10.x86_64 libselinux-debuginfo-3.9-1.el10.x86_64 libxcrypt-debuginfo-4.4.36-10.el10.x86_64 pcre2-debuginfo-10.44-1.el10.3.x86_64
(gdb) bt
#0  0x000000000807dff0 in ?? ()
#1  0x0000000000f2fa85 in std::default_delete<StackStringStream<4096ul> >::operator() (this=0x2e49310, __ptr=0x7d61f80)
    at /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/unique_ptr.h:93
#2  std::unique_ptr<StackStringStream<4096ul>, std::default_delete<StackStringStream<4096ul> > >::~unique_ptr (this=0x2e49310)
    at /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/unique_ptr.h:399
#3  std::destroy_at<std::unique_ptr<StackStringStream<4096ul>, std::default_delete<StackStringStream<4096ul> > > > (__location=0x2e49310)
    at /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/stl_construct.h:88
#4  std::allocator_traits<std::allocator<std::unique_ptr<StackStringStream<4096ul>, std::default_delete<StackStringStream<4096ul> > > > >::destroy<std::unique_ptr<StackStringStream<4096ul>, std::default_delete<StackStringStream<4096ul> > > > (__p=0x2e49310, __a=...) at /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/alloc_traits.h:599
#5  std::vector<std::unique_ptr<StackStringStream<4096ul>, std::default_delete<StackStringStream<4096ul> > >, std::allocator<std::unique_ptr<StackStringStream<4096ul>, std::default_delete<StackStringStream<4096ul> > > > >::pop_back (this=<optimized out>) at /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/stl_vector.h:1341
#6  CachedStackStringStream::CachedStackStringStream (this=0x7fff81fd0138) at /disk1/src-git/ceph--up--main/src/common/StackStringStream.h:138
#7  0x000000000127808f in evaluate_iam_policies (dpp=dpp@entry=0x792b200, env=..., identity=..., account_root=<optimized out>, op=op@entry=2, arn=..., resource_policy=..., 
    identity_policies=std::vector of length 0, capacity 0, session_policies=std::vector of length 0, capacity 0) at /disk1/src-git/ceph--up--main/src/rgw/rgw_common.cc:1263
#8  0x000000000127a03e in verify_bucket_permission (dpp=dpp@entry=0x792b200, s=s@entry=0x7fff81fd04f8, arn=..., account_root=false, user_acl=..., bucket_acl=..., bucket_policy=..., 
    identity_policies=std::vector of length 0, capacity 0, session_policies=std::vector of length 0, capacity 0, op=2, granted_by_acl=0x7fff81fd2239)
    at /disk1/src-git/ceph--up--main/src/rgw/rgw_common.cc:1386
#9  0x000000000127aef3 in verify_bucket_permission (dpp=dpp@entry=0x792b200, s=s@entry=0x7fff81fd1708, arn=..., user_acl=..., bucket_acl=..., bucket_policy=..., 
    user_policies=std::vector of length 0, capacity 0, session_policies=std::vector of length 0, capacity 0, op=2) at /disk1/src-git/ceph--up--main/src/rgw/rgw_common.cc:1440
#10 0x000000000127bf78 in verify_bucket_permission (dpp=0x7d61f80, dpp@entry=0x792b200, s=0x6c6f6f705f7478, s@entry=0x7fff81fd1708, arn=..., op=127167992, op@entry=2)
    at /disk1/src-git/ceph--up--main/src/rgw/rgw_common.cc:1505
#11 0x00000000013a7464 in RGWPutObj::verify_permission (this=0x792b200, y=...) at /disk1/src-git/ceph--up--main/src/rgw/rgw_op.cc:4404
#12 0x00000000010cb00a in rgw_process_authenticated (handler=handler@entry=0x8290220, op=@0x7fff81fd1650: 0x792b200, req=req@entry=0x7fff81fd2790, s=s@entry=0x7fff81fd1708, y=y@entry=..., 
    driver=driver@entry=0x2e13e00, skip_retarget=<optimized out>) at /disk1/src-git/ceph--up--main/src/rgw/rgw_process.cc:239
#13 0x00000000010ce4f1 in process_request (penv=..., req=req@entry=0x7fff81fd2790, frontend_prefix=..., client_io=client_io@entry=0x7fff81fd2838, yield=yield@entry=..., scheduler=0x4146308, 
    user=0x7fff81fd2818, latency=0x7fff81fd2780, http_ret=0x7fff81fd278c) at /disk1/src-git/ceph--up--main/src/rgw/rgw_process.cc:454
#14 0x00000000010249bf in (anonymous namespace)::handle_connection<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor> > (context=..., env=..., stream=..., 
    timeout=..., header_limit=header_limit@entry=16384, buffer=..., is_ssl=false, pause_mutex=..., scheduler=0x4146308, uri_prefix="", ec=..., yield=...)
    at /disk1/src-git/ceph--up--main/src/rgw/rgw_asio_frontend.cc:355
#15 0x0000000001023067 in (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_1::operator()(boost::asio::basic_yield_context<boost::asio::any_io_executor>) (this=0x7fff81fd3ce8, yield=...) at /disk1/src-git/ceph--up--main/src/rgw/rgw_asio_frontend.cc:1250
#16 boost::asio::detail::spawn_entry_point<boost::asio::strand<boost::asio::io_context::basic_executor_type<std::allocator<void>, 0ul> >, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_1, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_3>::call (this=0x7fff81fd3cd0, yield=...)
    at boost/include/boost/asio/impl/spawn.hpp:748
#17 boost::asio::detail::spawn_entry_point<boost::asio::strand<boost::asio::io_context::basic_executor_type<std::allocator<void>, 0ul> >, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_1, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_3>::operator() (this=0x7fff81fd3cd0, spawned_thread=0x7fff81fd3c40)
    at boost/include/boost/asio/impl/spawn.hpp:737
#18 boost::asio::detail::spawned_fiber_thread::entry_point<boost::asio::detail::spawn_entry_point<boost::asio::strand<boost::asio::io_context::basic_executor_type<std::allocator<void>, 0ul> >, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_1, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_3> >::operator()
    (this=0x7fff81fd3f20, caller=...) at boost/include/boost/asio/impl/spawn.hpp:152
#19 std::__invoke_impl<boost::context::fiber, boost::asio::detail::spawned_fiber_thread::entry_point<boost::asio::detail::spawn_entry_point<boost::asio::strand<boost::asio::io_context::basic_executor_type<std::allocator<void>, 0ul> >, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_1, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_3> >&, boost::context::fiber> (__f=..., __args=...) at /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/invoke.h:61
#20 std::__invoke<boost::asio::detail::spawned_fiber_thread::entry_point<boost::asio::detail::spawn_entry_point<boost::asio::strand<boost::asio::io_context::basic_executor_type<std::allocator<void>, 0ul> >, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_1, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_3> >&, boost::context::fiber> (__fn=..., __args=...) at /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/invoke.h:96
#21 std::invoke<boost::asio::detail::spawned_fiber_thread::entry_point<boost::asio::detail::spawn_entry_point<boost::asio::strand<boost::asio::io_context::basic_executor_type<std::allocator<void>, 0ul> >, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_1, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_3> >&, boost::context::fiber> (__fn=..., __args=...) at /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/functional:120
#22 boost::context::detail::fiber_record<boost::context::fiber, boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>, boost::asio::detail::spawned_fiber_thread::entry_point<boost::asio::detail::spawn_entry_point<boost::asio::strand<boost::asio::io_context::basic_executor_type<std::allocator<void>, 0ul> >, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_1, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_3> > >::run (this=0x7fff81fd3f00, fctx=<optimized out>)
    at boost/include/boost/context/fiber_fcontext.hpp:157
#23 boost::context::detail::fiber_entry<boost::context::detail::fiber_record<boost::context::fiber, boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>, boost::asio::detail::spawned_fiber_thread::entry_point<boost::asio::detail::spawn_entry_point<boost::asio::strand<boost::asio::io_context::basic_executor_type<std::allocator<void>, 0ul> >, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_1, (anonymous namespace)::AsioFrontend::on_accept((anonymous namespace)::AsioFrontend::Listener&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>)::$_3> > > > (t=...)
    at boost/include/boost/context/fiber_fcontext.hpp:97
#24 0x00000000021e913f in make_fcontext ()
#25 0x0000000000000000 in ?? ()

(the workload is PUT of 4KB objects using ~64 concurrent requests on a machine with 128 cores)

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions Bot added the stale label Jul 2, 2026
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no activity for 90 days. Please feel free to reopen this pull request (or open a new one) if the proposed change is still appropriate. Thank you for your contribution!

@github-actions github-actions Bot closed this Aug 1, 2026
@adamemerson
adamemerson deleted the wip-stackstream-post-destruct-access branch August 4, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants