Skip to content

Continue receiving data for the current messages, even when we select… #1382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,9 @@ bool CConnman::GenerateSelectSet(const std::vector<CNode*>& 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
Expand All @@ -1445,7 +1448,9 @@ bool CConnman::GenerateSelectSet(const std::vector<CNode*>& 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());
Expand Down
6 changes: 6 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -363,6 +365,10 @@ class V1TransportDeserializer final : public TransportDeserializer
Reset();
}

bool IsEmpty() const override
{
return (nHdrPos == 0);
}
bool Complete() const override
{
if (!in_data)
Expand Down