Skip to content

Commit 9ef0265

Browse files
committed
Merge branch 'master-fix-stall' into elements-22-fix-ci
2 parents b37e09c + b2ce24c commit 9ef0265

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/net.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,9 @@ bool CConnman::GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &s
13611361
// write buffer in this case before receiving more. This avoids
13621362
// needlessly queueing received data, if the remote peer is not themselves
13631363
// receiving data. This means properly utilizing TCP flow control signalling.
1364+
// This logic can put both nodes in deadlock if they are both "not receiving",
1365+
// so there is a special case where we only stop receiving new messages, but
1366+
// keep processing the in-progress ones.
13641367
// * Otherwise, if there is space left in the receive buffer, select() for
13651368
// receiving data.
13661369
// * Hand off all complete messages to the processor, to be handled without
@@ -1380,7 +1383,9 @@ bool CConnman::GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &s
13801383
error_set.insert(pnode->hSocket);
13811384
if (select_send) {
13821385
send_set.insert(pnode->hSocket);
1383-
continue;
1386+
// Only stop receiving new messages, but keep processing incomplete ones
1387+
if (!pnode->m_deserializer->IsEmpty())
1388+
continue;
13841389
}
13851390
if (select_recv) {
13861391
recv_set.insert(pnode->hSocket);

src/net.h

+6
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ class CNetMessage {
302302
*/
303303
class TransportDeserializer {
304304
public:
305+
// returns true if the current deserialization is empty
306+
virtual bool IsEmpty() const = 0;
305307
// returns true if the current deserialization is complete
306308
virtual bool Complete() const = 0;
307309
// set the serialization context version
@@ -352,6 +354,10 @@ class V1TransportDeserializer final : public TransportDeserializer
352354
Reset();
353355
}
354356

357+
bool IsEmpty() const override
358+
{
359+
return (nHdrPos == 0);
360+
}
355361
bool Complete() const override
356362
{
357363
if (!in_data)

0 commit comments

Comments
 (0)