Skip to content

Commit a099875

Browse files
authoredMar 26, 2020
Connection: Fix deadlock in debug mode (#9550)
1 parent f7c7353 commit a099875

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed
 

‎src/network/connection.cpp

+21-11
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,23 @@ namespace con
4141
/* defines used for debugging and profiling */
4242
/******************************************************************************/
4343
#ifdef NDEBUG
44-
#define LOG(a) a
45-
#define PROFILE(a)
44+
#define LOG(a) a
45+
#define PROFILE(a)
4646
#else
47-
/* this mutex is used to achieve log message consistency */
48-
std::mutex log_message_mutex;
49-
#define LOG(a) \
50-
{ \
51-
MutexAutoLock loglock(log_message_mutex); \
52-
a; \
53-
}
54-
#define PROFILE(a) a
47+
#if 0
48+
/* this mutex is used to achieve log message consistency */
49+
std::mutex log_message_mutex;
50+
#define LOG(a) \
51+
{ \
52+
MutexAutoLock loglock(log_message_mutex); \
53+
a; \
54+
}
55+
#else
56+
// Prevent deadlocks until a solution is found after 5.2.0 (TODO)
57+
#define LOG(a) a
58+
#endif
59+
60+
#define PROFILE(a) a
5561
#endif
5662

5763
#define PING_TIMEOUT 5.0
@@ -1073,6 +1079,10 @@ bool UDPPeer::processReliableSendCommand(
10731079
FATAL_ERROR_IF(!successfully_put_back_sequence_number, "error");
10741080
}
10751081

1082+
// DO NOT REMOVE n_queued! It avoids a deadlock of async locked
1083+
// 'log_message_mutex' and 'm_list_mutex'.
1084+
u32 n_queued = channels[c.channelnum].outgoing_reliables_sent.size();
1085+
10761086
LOG(dout_con<<m_connection->getDesc()
10771087
<< " Windowsize exceeded on reliable sending "
10781088
<< c.data.getSize() << " bytes"
@@ -1081,7 +1091,7 @@ bool UDPPeer::processReliableSendCommand(
10811091
<< std::endl << "\t\tgot at most : "
10821092
<< packets_available << " packets"
10831093
<< std::endl << "\t\tpackets queued : "
1084-
<< channels[c.channelnum].outgoing_reliables_sent.size()
1094+
<< n_queued
10851095
<< std::endl);
10861096

10871097
return false;

0 commit comments

Comments
 (0)
Please sign in to comment.