]> granicus.if.org Git - pdns/commitdiff
fix confusing error on TCP/IP disconnect at just the right time (about 'endpoint...
authorbert hubert <bert.hubert@netherlabs.nl>
Mon, 6 Jun 2016 19:30:58 +0000 (21:30 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Mon, 6 Jun 2016 19:30:58 +0000 (21:30 +0200)
pdns/tcpreceiver.cc

index 3ac1b9a843c7eeb7812a11b604ba2f7c0378c0e7..6ade029f65dc931f0ca6dc6dedff48d1df77bd09 100644 (file)
@@ -253,7 +253,17 @@ void *TCPNameserver::doConnection(void *data)
   shared_ptr<DNSPacket> packet;
   // Fix gcc-4.0 error (on AMD64)
   int fd=(int)(long)data; // gotta love C (generates a harmless warning on opteron)
+  ComboAddress remote;
+  socklen_t remotelen=sizeof(remote);
+
   pthread_detach(pthread_self());
+  if(getpeername(fd, (struct sockaddr *)&remote, &remotelen) < 0) {
+    L<<Logger::Warning<<"Received question from socket which had no remote address, dropping ("<<stringerror()<<")"<<endl;
+    d_connectionroom_sem->post();
+    closesocket(fd);
+    return 0;
+  }
+
   setNonBlocking(fd);
   try {
     int mesgsize=65535;
@@ -262,12 +272,6 @@ void *TCPNameserver::doConnection(void *data)
     DLOG(L<<"TCP Connection accepted on fd "<<fd<<endl);
     bool logDNSQueries= ::arg().mustDo("log-dns-queries");
     for(;;) {
-      ComboAddress remote;
-      socklen_t remotelen=sizeof(remote);
-      if(getpeername(fd, (struct sockaddr *)&remote, &remotelen) < 0) {
-        L<<Logger::Warning<<"Received question from socket which had no remote address, dropping ("<<stringerror()<<")"<<endl;
-        break;
-      }
 
       uint16_t pktlen;
       if(!readnWithTimeout(fd, &pktlen, 2, false))