Skip to content

Keep io_context alive in socket_base via shared_ptr to prevent premature destruction#5014

Merged
pwojcikdev merged 3 commits intonanocurrency:developfrom
pwojcikdev:ipc-ctx-lifetimes
Jan 28, 2026
Merged

Keep io_context alive in socket_base via shared_ptr to prevent premature destruction#5014
pwojcikdev merged 3 commits intonanocurrency:developfrom
pwojcikdev:ipc-ctx-lifetimes

Conversation

@pwojcikdev
Copy link
Copy Markdown
Contributor

Should fix sanitizer error in rpc_test where deadline_timer accesses destroyed io_context:

Report: sanitizer_report.rpc_test.71093
  /Users/runner/work/nano-node/nano-node/submodules/boost/libs/asio/include/boost/asio/basic_deadline_timer.hpp:548:41: runtime error: member call on address 0x6000004715e0 which does not point to an object of type 'boost::asio::detail::deadline_timer_service<boost::asio::time_traits<boost::posix_time::ptime>>'
  0x6000004715e0: note: object has invalid vptr
   00 00 00 00  e0 15 bb 31 5f 00 00 00  45 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
                ^~~~~~~~~~~~~~~~~~~~~~~
                invalid vptr

@gr0vity-dev-bot
Copy link
Copy Markdown

gr0vity-dev-bot commented Jan 26, 2026

Test Results for Commit f2bd7e3

Pull Request 5014: Results
Overall Status:

Test Case Results

  • 5n4pr_conf_10k_bintree: PASS (Duration: 112s)
  • 5n4pr_conf_10k_change: PASS (Duration: 357s)
  • 5n4pr_conf_change_dependant: PASS (Duration: 126s)
  • 5n4pr_conf_change_independant: PASS (Duration: 152s)
  • 5n4pr_conf_send_dependant: PASS (Duration: 150s)
  • 5n4pr_conf_send_independant: PASS (Duration: 131s)
  • 5n4pr_rocks_10k_bintree: PASS (Duration: 238s)
  • 5n4pr_rocks_10k_change: PASS (Duration: 139s)

Last updated: 2026-01-27 17:20:00 UTC

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a sanitizer error where a deadline_timer could access a destroyed io_context by keeping the io_context alive via shared_ptr in socket_base. The changes ensure that any socket object (session, socket_client, etc.) keeps the io_context alive for its entire lifetime.

Changes:

  • Modified socket_base to accept and store a shared_ptr<io_context> while providing a reference for derived classes to use
  • Updated all constructors of classes deriving from socket_base to accept shared_ptr<io_context> instead of references
  • Enhanced socket_transport::stop() to allow async handlers to complete before shutdown, ensuring proper cleanup

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
nano/lib/ipc.hpp Added shared_ptr storage to socket_base and updated constructor signature
nano/lib/ipc.cpp Implemented socket_base constructor to initialize reference from shared_ptr
nano/lib/ipc_client.hpp Updated ipc_client to accept shared_ptr io_context
nano/lib/ipc_client.cpp Updated socket_client and client_impl constructors to use shared_ptr
nano/node/ipc/ipc_server.hpp Minor formatting improvement (added blank line)
nano/node/ipc/ipc_server.cpp Updated session constructor, added session tracking, modified stop() to drain handlers
nano/rpc/rpc_request_processor.hpp Updated constructor signatures to accept shared_ptr
nano/rpc/rpc_request_processor.cpp Updated constructor implementations with shared_ptr
nano/rpc_test/rpc.cpp Updated call site to pass shared_ptr instead of reference
nano/rpc_test/rpc_context.cpp Updated call site to pass shared_ptr instead of reference
nano/slow_test/bootstrap.cpp Updated call site to pass shared_ptr instead of reference
nano/nano_rpc/entry.cpp Updated call site to pass shared_ptr instead of reference
nano/ipc_flatbuffers_test/entry.cpp Updated to create and use shared_ptr io_context
nano/core_test/ipc.cpp Updated to use node's io_ctx_shared instead of io_ctx reference

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pwojcikdev pwojcikdev merged commit b2d2578 into nanocurrency:develop Jan 28, 2026
32 checks passed
@pwojcikdev pwojcikdev deleted the ipc-ctx-lifetimes branch January 28, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants