Skip to content

Commit 17dca71

Browse files
committed
Fixed very rare bug where BitcoinD instances may become unresponsive
The symptom is one of the 3 BitcoinD instances in the app would stop working and continually attempt to reconnect to the remote bitcoind daemon, never quite succeeding and never receiving a ping reply. The way it could be triggered is if the remote daemon drops conn on us at an inopportune time while we are reading content from its HTTP response. The internal StateMachine used by this class would end up in a confused state. The fix is to implement `on_disconnected` in the HttpConnection class and be sure to reset the StateMachine for this instance on a connection drop. This fixes the bug nicely. The bug was extremely rare but not impossible.
1 parent d4b3fa1 commit 17dca71

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/RPC.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,11 @@ namespace RPC {
862862
qint64 largeContentT0 = 0;
863863
void clear() { *this = StateMachine(); }
864864
};
865+
void HttpConnection::on_disconnected()
866+
{
867+
ConnectionBase::on_disconnected(); // chain to super
868+
sm.reset(); // ensure statemachine is dead to prevent potential bugs we saw with bitcoind's going out to lunch due to wrong SM state after reconnect!
869+
}
865870
void HttpConnection::on_readyRead()
866871
{
867872
if (!sm)

src/RPC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ namespace RPC {
610610
protected:
611611
void on_readyRead() override;
612612
QByteArray wrapForSend(QByteArray &&) override;
613+
void on_disconnected() override;
613614

614615
private:
615616
/// These end up verbatim in the HTTP/1.1 POST header.

0 commit comments

Comments
 (0)