From: Ruben d'Arco Date: Sun, 3 Mar 2013 07:01:41 +0000 (+0100) Subject: Add lock to rfc2136 handling to fix deadlock issue X-Git-Tag: rec-3.6.0-rc1~556^2~3^2~62 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ee9ef8f2403983a6417346c592e8c24e48f9c611;p=thirdparty%2Fpdns.git Add lock to rfc2136 handling to fix deadlock issue We receive Mar 03 07:40:06 UPDATE (9044) from 127.0.0.3 for test.dyndns: Caught SSqlException: Failed to execute mysql_query, perhaps connection died? Err=1: Deadlock found when trying to get lock; try restarting transaction; Sending ServFail! if we don't. --- diff --git a/pdns/packethandler.hh b/pdns/packethandler.hh index c49bd6199b..1a00c11967 100755 --- a/pdns/packethandler.hh +++ b/pdns/packethandler.hh @@ -122,6 +122,7 @@ private: void completeANYRecords(DNSPacket *p, DNSPacket*r, SOAData& sd, const string &target); static AtomicCounter s_count; + static pthread_mutex_t s_rfc2136lock; bool d_doFancyRecords; bool d_doRecursion; bool d_doCNAME; diff --git a/pdns/rfc2136handler.cc b/pdns/rfc2136handler.cc index 2aa8139146..87c6c4c4ae 100755 --- a/pdns/rfc2136handler.cc +++ b/pdns/rfc2136handler.cc @@ -13,6 +13,8 @@ extern PacketCache PC; +pthread_mutex_t PacketHandler::s_rfc2136lock=PTHREAD_MUTEX_INITIALIZER; + // Implement section 3.2.1 and 3.2.2 of RFC2136 int PacketHandler::checkUpdatePrerequisites(const DNSRecord *rr, DomainInfo *di) { if (rr->d_ttl != 0) @@ -534,7 +536,7 @@ int PacketHandler::processUpdate(DNSPacket *p) { } } - //TODO: Start a lock here, to make section 3.7 correct??? + Lock l(&s_rfc2136lock); L<startTransaction(p->qdomain, -1)) { // Not giving the domain_id means that we do not delete the records. L<qdomain<<" does not support transaction. Can't do Update packet."<abortTransaction(); + return RCode::ServFail; + } catch (AhuException &e) { L<abortTransaction(); return RCode::ServFail; } + catch (SSqlException &e) { + L<abortTransaction(); + return RCode::ServFail; + } catch (...) { L<abortTransaction();