diff --git a/src/net.cpp b/src/net.cpp index 1b0e7369a3..944c49cceb 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1425,6 +1425,9 @@ bool CConnman::GenerateSelectSet(const std::vector& nodes, // write buffer in this case before receiving more. This avoids // needlessly queueing received data, if the remote peer is not themselves // receiving data. This means properly utilizing TCP flow control signalling. + // This logic can put both nodes in deadlock if they are both "not receiving", + // so there is a special case where we only stop receiving new messages, but + // keep processing the in-progress ones. // * Otherwise, if there is space left in the receive buffer, select() for // receiving data. // * Hand off all complete messages to the processor, to be handled without @@ -1445,7 +1448,9 @@ bool CConnman::GenerateSelectSet(const std::vector& nodes, error_set.insert(pnode->m_sock->Get()); if (select_send) { send_set.insert(pnode->m_sock->Get()); - continue; + // Only stop receiving new messages, but keep processing incomplete ones + if (pnode->m_deserializer->IsEmpty()) + continue; } if (select_recv) { recv_set.insert(pnode->m_sock->Get()); diff --git a/src/net.h b/src/net.h index 421e3a85a1..d34912c62b 100644 --- a/src/net.h +++ b/src/net.h @@ -313,6 +313,8 @@ class CNetMessage { */ class TransportDeserializer { public: + // returns true if the current deserialization is empty + virtual bool IsEmpty() const = 0; // returns true if the current deserialization is complete virtual bool Complete() const = 0; // set the serialization context version @@ -363,6 +365,10 @@ class V1TransportDeserializer final : public TransportDeserializer Reset(); } + bool IsEmpty() const override + { + return (nHdrPos == 0); + } bool Complete() const override { if (!in_data)