Parcourir la source

[trac775] fix the bug that if name server bind port failed, name server will exist, in that case, we can't reset the port number

hanfeng il y a 14 ans
Parent
commit
660d7d782c

+ 10 - 6
src/lib/server_common/portconfig.cc

@@ -95,11 +95,17 @@ installListenAddresses(const AddressList& newAddresses,
     }
     catch (const exception& e) {
         /*
-         * We couldn't set it. So return it back. If that fails as well,
-         * we have a problem.
+         * If one of the addresses isn't set successfully, we will restore
+         * the old addresses, the behavior is that either all address are
+         * set successuflly or none of them will be used. whether this
+         * behavior is user desired, maybe we need revisited it later. And
+         * if address setting is more smarter, it should check whether some
+         * part of the new address already in used to avoid interuption the
+         * service.
          *
-         * If that fails, bad luck, but we are useless anyway, so just die
-         * and let boss start us again.
+         * If the address setting still failed, we can live with it, since
+         * user will get error info, command control can be used to set new
+         * address. So we just catch the exception without propagating outside
          */
         dlog(string("Unable to set new address: ") + e.what(), true);
         try {
@@ -108,9 +114,7 @@ installListenAddresses(const AddressList& newAddresses,
         catch (const exception& e2) {
             dlog("Unable to recover from error;", true);
             dlog(string("Rollback failed with: ") + e2.what(), true);
-            abort();
         }
-        throw; // Let it fly a little bit further
     }
 }
 

+ 1 - 1
src/lib/server_common/tests/portconfig_unittest.cc

@@ -175,7 +175,7 @@ TEST_F(InstallListenAddresses, rollback) {
     EXPECT_NO_THROW(installListenAddresses(valid_, store_, dnss_));
     checkAddresses(valid_, "Before rollback");
     // This should not bind them, but should leave the original addresses
-    EXPECT_THROW(installListenAddresses(invalid_, store_, dnss_), IOError);
+    EXPECT_NO_THROW(installListenAddresses(invalid_, store_, dnss_));
     checkAddresses(valid_, "After rollback");
 }