[glom] Self-Hosting: Don't keep trying indefinitely when trying various ports.



commit eb2a2550933f989e1031f42dbbf3edc9ced99d48
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Aug 9 14:39:09 2010 +0200

    Self-Hosting: Don't keep trying indefinitely when trying various ports.
    
    * glom/libglom/connectionpool_backends/postgres_self.cc: connect():
      Fix a logic error introcuced when removing the no-exceptions ifdefs.
      Now it only retries when a particular type of error happens, and otherwise
      fails.

 ChangeLog                                          |   11 ++++++-
 .../connectionpool_backends/postgres_self.cc       |   34 +++++++++++---------
 2 files changed, 29 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index cc47f7a..e1cdf4a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2010-08-09  Murray Cumming  <murrayc murrayc com>
+
+	Self-Hosting: Don't keep trying indefinitely when trying various ports.
+
+	* glom/libglom/connectionpool_backends/postgres_self.cc: connect():
+  Fix a logic error introcuced when removing the no-exceptions ifdefs.
+  Now it only retries when a particular type of error happens, and otherwise
+  fails.
+
 2010-08-07  Murray Cumming  <murrayc murrayc com>
 
 	Fix the tests.
@@ -177,7 +186,7 @@
 2010-07-27  Murray Cumming  <murrayc murrayc com>
 
 	Fix the tests build after the merge.
-	
+
 	* tests/test_selfhosting_new_empty.cc: Fix the use of Utils::.
 
 2010-07-27  Murray Cumming  <murrayc murrayc com>
diff --git a/glom/libglom/connectionpool_backends/postgres_self.cc b/glom/libglom/connectionpool_backends/postgres_self.cc
index 8055723..037bc28 100644
--- a/glom/libglom/connectionpool_backends/postgres_self.cc
+++ b/glom/libglom/connectionpool_backends/postgres_self.cc
@@ -275,7 +275,7 @@ Glib::ustring PostgresSelfHosted::get_postgresql_utils_version(const SlotProgres
   {
     std::cerr << "Glom: Glib::Regex::create() failed: " << ex.what() << std::endl;
     return result;
-  } 
+  }
 
   if(!regex)
     return result;
@@ -317,7 +317,7 @@ float PostgresSelfHosted::get_postgresql_utils_version_as_number(const SlotProgr
   {
     std::cerr << "Glom: Glib::Regex::create() failed: " << ex.what() << std::endl;
     return result;
-  } 
+  }
 
   if(!regex)
     return result;
@@ -568,12 +568,12 @@ Glib::RefPtr<Gnome::Gda::Connection> PostgresSelfHosted::connect(const Glib::ust
     {
       result = attempt_connect(port_as_string(m_port), database, username, password);
     }
-    catch(const ExceptionConnection ex)
+    catch(const ExceptionConnection& ex)
     {
       if(ex.get_failure_type() == ExceptionConnection::FAILURE_NO_SERVER)
       {
         //It must be using a default password, so any failure would not be due to a wrong password.
-        //However, pg_ctl sometimes reports success before it is really ready to let us connect, 
+        //However, pg_ctl sometimes reports success before it is really ready to let us connect,
         //so in this case we can just keep trying until it works, with a very long timeout.
         count_retries++;
         const guint max_retries = m_network_shared ? MAX_RETRIES_EVER : MAX_RETRIES_KNOWN_PASSWORD;
@@ -582,20 +582,24 @@ Glib::RefPtr<Gnome::Gda::Connection> PostgresSelfHosted::connect(const Glib::ust
           keep_trying = false;
           continue;
         }
-      }
 
-      std::cout << "debug: " << G_STRFUNC << ": Waiting and retrying the connection due to suspected too-early success of pg_ctl." << std::endl; 
+        std::cout << "debug: " << G_STRFUNC << ": Waiting and retrying the connection due to suspected too-early success of pg_ctl. retries=" << count_retries << ", max_retries=" << m_network_shared << std::endl;
 
-      //Wait:
-      Glib::RefPtr<Glib::MainLoop> mainloop = Glib::MainLoop::create(false);
-        sigc::connection connection_timeout = Glib::signal_timeout().connect(
-        sigc::bind(sigc::ptr_fun(&on_timeout_delay), sigc::ref(mainloop)),
-        1000 /* 1 second */);
-      mainloop->run();
-      connection_timeout.disconnect();
+        //Wait:
+        Glib::RefPtr<Glib::MainLoop> mainloop = Glib::MainLoop::create(false);
+          sigc::connection connection_timeout = Glib::signal_timeout().connect(
+          sigc::bind(sigc::ptr_fun(&on_timeout_delay), sigc::ref(mainloop)),
+          1000 /* 1 second */);
+        mainloop->run();
+        connection_timeout.disconnect();
 
-      keep_trying = true;
-      continue;
+        keep_trying = true;
+        continue;
+      }
+      else
+      {
+        throw ex;
+      }
     }
 
     keep_trying = false;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]