From: Kees Monshouwer Date: Thu, 30 Jun 2016 20:35:41 +0000 (+0200) Subject: retry once after a backend failure X-Git-Tag: rec-4.0.0~18^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bf17c14b4d9bdd07dd04512028c328b053ba0a9c;p=thirdparty%2Fpdns.git retry once after a backend failure --- diff --git a/pdns/distributor.hh b/pdns/distributor.hh index b506071ee5..d1940ec691 100644 --- a/pdns/distributor.hh +++ b/pdns/distributor.hh @@ -196,41 +196,57 @@ templatevoid *MultiThreadDistributo S.inc("timedout-packets"); continue; } + + bool allowRetry=true; +retry: // this is the only point where we interact with the backend (synchronous) try { - if (!b) + if (!b) { + allowRetry=false; b=new Backend(); - a=b->question(QD->Q); - delete QD->Q; + } + a=b->question(QD->Q); + delete QD->Q; } catch(const PDNSException &e) { - L<Q->replyPacket(); - - a->setRcode(RCode::ServFail); - S.inc("servfail-packets"); - S.ringAccount("servfail-queries",QD->Q->qdomain.toString()); - - delete QD->Q; + if (!allowRetry) { + L<Q->replyPacket(); + + a->setRcode(RCode::ServFail); + S.inc("servfail-packets"); + S.ringAccount("servfail-queries",QD->Q->qdomain.toString()); + + delete QD->Q; + } else { + L<Q->replyPacket(); - - a->setRcode(RCode::ServFail); - S.inc("servfail-packets"); - S.ringAccount("servfail-queries",QD->Q->qdomain.toString()); - delete QD->Q; + delete b; + b=NULL; + if (!allowRetry) { + L<Q->replyPacket(); + + a->setRcode(RCode::ServFail); + S.inc("servfail-packets"); + S.ringAccount("servfail-queries",QD->Q->qdomain.toString()); + + delete QD->Q; + } else { + L<callback(a); delete QD; } - + delete b; } catch(const PDNSException &AE) { @@ -247,28 +263,44 @@ templatevoid *MultiThreadDistributo templateint SingleThreadDistributor::question(Question* q, callback_t callback) { Answer *a; + bool allowRetry=true; +retry: try { - if (!b) + if (!b) { + allowRetry=false; b=new Backend; + } a=b->question(q); // a can be NULL! } catch(const PDNSException &e) { - L<replyPacket(); - a->setRcode(RCode::ServFail); - S.inc("servfail-packets"); - S.ringAccount("servfail-queries",q->qdomain.toString()); + if (!allowRetry) { + L<replyPacket(); + + a->setRcode(RCode::ServFail); + S.inc("servfail-packets"); + S.ringAccount("servfail-queries",q->qdomain.toString()); + } else { + L<replyPacket(); - a->setRcode(RCode::ServFail); - S.inc("servfail-packets"); - S.ringAccount("servfail-queries",q->qdomain.toString()); + if (!allowRetry) { + L<replyPacket(); + + a->setRcode(RCode::ServFail); + S.inc("servfail-packets"); + S.ringAccount("servfail-queries",q->qdomain.toString()); + } else { + L<