Skip to content

Commit

Permalink
Revert "GH-819 Simplify code by running listener on the main thread"
Browse files Browse the repository at this point in the history
This reverts commit 6b5ab76.
  • Loading branch information
heifner committed Oct 8, 2024
1 parent 3bb1a81 commit db2dcc4
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions plugins/state_history_plugin/state_history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,26 @@ struct state_history_plugin_impl {
template <typename Protocol>
void create_listener(const std::string& address) {
const boost::posix_time::milliseconds accept_timeout(200);
// connections set must only be modified by main thread; run listener on main thread so callback is on main thread
fc::create_listener<Protocol>(app().get_io_service(), _log, accept_timeout, address, "",
// connections set must only be modified by main thread; run listener on ship thread so sockets use default executor of the ship thread
fc::create_listener<Protocol>(thread_pool.get_executor(), _log, accept_timeout, address, "",
[this](const auto&) { return boost::asio::make_strand(thread_pool.get_executor()); },
[this](Protocol::socket&& socket) {
catch_and_log([this, &socket]() {
connections.emplace(new session(std::move(socket), chain_plug->chain(),
trace_log, chain_state_log, finality_data_log,
[this](const chain::block_num_type block_num) {
return get_block_id(block_num);
},
[this](const chain::block_id_type& block_id) {
return chain_plug->chain().fetch_block_by_id(block_id);
},
[this](session_base* conn) {
boost::asio::post(app().get_io_service(), [conn, this]() {
connections.erase(connections.find(conn));
});
}, _log));
boost::asio::post(app().get_io_service(), [this, socket{std::move(socket)}]() mutable {
catch_and_log([this, &socket]() {
connections.emplace(new session(std::move(socket), chain_plug->chain(),
trace_log, chain_state_log, finality_data_log,
[this](const chain::block_num_type block_num) {
return get_block_id(block_num);
},
[this](const chain::block_id_type& block_id) {
return chain_plug->chain().fetch_block_by_id(block_id);
},
[this](session_base* conn) {
boost::asio::post(app().get_io_service(), [conn, this]() {
connections.erase(connections.find(conn));
});
}, _log));
});
});
});
}
Expand Down

0 comments on commit db2dcc4

Please sign in to comment.