Keep io_context alive in socket_base via shared_ptr to prevent premature destruction#5014
Merged
pwojcikdev merged 3 commits intonanocurrency:developfrom Jan 28, 2026
Merged
Conversation
Test Results for Commit f2bd7e3Pull Request 5014: Results Test Case Results
Last updated: 2026-01-27 17:20:00 UTC |
5faac91 to
9d070d0
Compare
Contributor
There was a problem hiding this comment.
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_baseto accept and store ashared_ptr<io_context>while providing a reference for derived classes to use - Updated all constructors of classes deriving from
socket_baseto acceptshared_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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Should fix sanitizer error in rpc_test where deadline_timer accesses destroyed io_context: