From c581cc16bb5e490c0960ccf440de2d1e5f23c417 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 17 Apr 2012 18:50:45 +0200 Subject: [PATCH] Fix potential deadlock Conflict: * cs_main in ProcessMessages() (before calling ProcessMessages) * cs_vSend in CNode::BeginMessage versus: * cs_vSend in ThreadMessageHandler2 (before calling SendMessages) * cs_main in SendMessages Even though cs_vSend is a try_lock, if it succeeds simultaneously with the locking of cs_main in ProcessMessages(), it could cause a deadlock. --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f2932804e37..3396fe1911e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2807,8 +2807,8 @@ bool ProcessMessages(CNode* pfrom) bool SendMessages(CNode* pto, bool fSendTrickle) { - { - LOCK(cs_main); + TRY_LOCK(cs_main, lockMain); + if (lockMain) { // Don't send anything until we get their version message if (pto->nVersion == 0) return true;