aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2011-09-07 18:57:11 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2011-09-07 18:57:11 +0200
commita0d2f9a12dad7b33a3f12d85dee8afa4155dbc99 (patch)
tree24a475fe47ed00837fbed1836d03d933cfe7dbb2 /src/net.cpp
parentf077d1ad62cba26b2620c87abba87be7fec15f0d (diff)
parentf92f022edaa2f14951b9ce8304a304ff9693ae16 (diff)
downloadbitcoin-a0d2f9a12dad7b33a3f12d85dee8afa4155dbc99.tar.xz
Merge branch 'master' of https://github.com/bitcoin/bitcoin
Conflicts: .gitignore
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 5fca17aa46..509d8905f9 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -443,6 +443,10 @@ bool AddAddress(CAddress addr, int64 nTimePenalty, CAddrDB *pAddrDB)
if (addr.ip == addrLocalHost.ip)
return false;
addr.nTime = max((int64)0, (int64)addr.nTime - nTimePenalty);
+ bool fUpdated = false;
+ bool fNew = false;
+ CAddress addrFound = addr;
+
CRITICAL_BLOCK(cs_mapAddresses)
{
map<vector<unsigned char>, CAddress>::iterator it = mapAddresses.find(addr.GetKey());
@@ -451,16 +455,12 @@ bool AddAddress(CAddress addr, int64 nTimePenalty, CAddrDB *pAddrDB)
// New address
printf("AddAddress(%s)\n", addr.ToString().c_str());
mapAddresses.insert(make_pair(addr.GetKey(), addr));
- if (pAddrDB)
- pAddrDB->WriteAddress(addr);
- else
- CAddrDB().WriteAddress(addr);
- return true;
+ fUpdated = true;
+ fNew = true;
}
else
{
- bool fUpdated = false;
- CAddress& addrFound = (*it).second;
+ addrFound = (*it).second;
if ((addrFound.nServices | addr.nServices) != addrFound.nServices)
{
// Services have been added
@@ -475,16 +475,22 @@ bool AddAddress(CAddress addr, int64 nTimePenalty, CAddrDB *pAddrDB)
addrFound.nTime = addr.nTime;
fUpdated = true;
}
- if (fUpdated)
- {
- if (pAddrDB)
- pAddrDB->WriteAddress(addrFound);
- else
- CAddrDB().WriteAddress(addrFound);
- }
}
}
- return false;
+ // There is a nasty deadlock bug if this is done inside the cs_mapAddresses
+ // CRITICAL_BLOCK:
+ // Thread 1: begin db transaction (locks inside-db-mutex)
+ // then AddAddress (locks cs_mapAddresses)
+ // Thread 2: AddAddress (locks cs_mapAddresses)
+ // ... then db operation hangs waiting for inside-db-mutex
+ if (fUpdated)
+ {
+ if (pAddrDB)
+ pAddrDB->WriteAddress(addrFound);
+ else
+ CAddrDB().WriteAddress(addrFound);
+ }
+ return fNew;
}
void AddressCurrentlyConnected(const CAddress& addr)