Skip to content

Commit 31c2687

Browse files
authored
Merge pull request #1446 from AntelopeIO/drain_ship_session_strand_11x
[1.1.5] fix state history race on disconnect: drain session strand before destroying session
2 parents ce3ceda + 3484726 commit 31c2687

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class session_base {
2525

2626
virtual void block_applied(const chain::block_num_type applied_block_num) = 0;
2727

28+
virtual void drain_strand() = 0;
29+
2830
virtual ~session_base() = default;
2931
};
3032

@@ -53,6 +55,11 @@ class session final : public session_base {
5355
awake_if_idle();
5456
}
5557

58+
// allow main thread to drain the strand before destruction -- some awake_if_idle() post()s may be inflight
59+
void drain_strand() {
60+
boost::asio::post(strand, boost::asio::use_future([](){})).get();
61+
}
62+
5663
private:
5764
std::string get_remote_endpoint_string() const {
5865
try {

plugins/state_history_plugin/state_history_plugin.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ struct state_history_plugin_impl {
117117
},
118118
[this](session_base* conn) {
119119
app().executor().post(priority::high, exec_queue::read_write, [conn, this]() {
120+
//Main thread may have post()s inflight to session strand (via block_applied() -> awake_if_idle()) that
121+
// could execute during destruction. Drain any possible post() before destruction. This is in main
122+
// thread now so guaranteed no new block_applied() will be called during these lines below, and the
123+
// session has already indicated it is "done" so it will not be running any operations of its own
124+
// on the strand
125+
conn->drain_strand();
120126
connections.erase(connections.find(conn));
121127
});
122128
}, _log));

0 commit comments

Comments
 (0)