template<class Answer, class Question, class Backend>SingleThreadDistributor<Answer,Question,Backend>::SingleThreadDistributor()
{
L<<Logger::Error<<"Only asked for 1 backend thread - operating unthreaded"<<endl;
- b=new Backend;
+ try {
+ b=new Backend;
+ }
+ catch(const PDNSException &AE) {
+ L<<Logger::Error<<"Distributor caught fatal exception: "<<AE.reason<<endl;
+ exit(1);
+ }
+ catch(...) {
+ L<<Logger::Error<<"Caught an unknown exception when creating backend, probably"<<endl;
+ exit(1);
+ }
}
template<class Answer, class Question, class Backend>MultiThreadDistributor<Answer,Question,Backend>::MultiThreadDistributor(int n)
}
// this is the only point where we interact with the backend (synchronous)
try {
+ if (!b)
+ b=new Backend();
a=b->question(QD->Q);
delete QD->Q;
}
catch(const PDNSException &e) {
L<<Logger::Error<<"Backend error: "<<e.reason<<endl;
delete b;
- b=new Backend();
+ b=NULL;
a=QD->Q->replyPacket();
a->setRcode(RCode::ServFail);
catch(...) {
L<<Logger::Error<<"Caught unknown exception in Distributor thread "<<(long)pthread_self()<<endl;
delete b;
- b=new Backend();
+ b=NULL;
a=QD->Q->replyPacket();
a->setRcode(RCode::ServFail);
}
catch(const PDNSException &AE) {
L<<Logger::Error<<"Distributor caught fatal exception: "<<AE.reason<<endl;
+ exit(1);
}
catch(...) {
L<<Logger::Error<<"Caught an unknown exception when creating backend, probably"<<endl;
+ exit(1);
}
return 0;
}
{
Answer *a;
try {
+ if (!b)
+ b=new Backend;
a=b->question(q); // a can be NULL!
}
catch(const PDNSException &e) {
L<<Logger::Error<<"Backend error: "<<e.reason<<endl;
delete b;
- b=new Backend;
+ b=NULL;
a=q->replyPacket();
a->setRcode(RCode::ServFail);
S.inc("servfail-packets");
catch(...) {
L<<Logger::Error<<"Caught unknown exception in Distributor thread "<<(unsigned long)pthread_self()<<endl;
delete b;
- b=new Backend;
+ b=NULL;
a=q->replyPacket();
a->setRcode(RCode::ServFail);
S.inc("servfail-packets");
L<<Logger::Error<<"Cleaning up"<<endl;
for(vector<DNSBackend *>::const_iterator i=ret.begin();i!=ret.end();++i)
delete *i;
- exit(1);
+ throw;
} catch(...) {
// and cleanup
L<<Logger::Error<<"Caught an exception instantiating a backend, cleaning up"<<endl;
for(vector<DNSBackend *>::const_iterator i=ret.begin();i!=ret.end();++i)
delete *i;
- exit(1);
+ throw;
}
return ret;