Try connecting to the SHAR multiple times (with a short sleep between).
authorDerek Atkins <derek@ihtfp.com>
Tue, 15 Oct 2002 16:11:28 +0000 (16:11 +0000)
committerDerek Atkins <derek@ihtfp.com>
Tue, 15 Oct 2002 16:11:28 +0000 (16:11 +0000)
Log heavier if it fails (to the log4cpp log)
Throw a ShibTargetException (instead of a runtime_error)
Catch the exception and print an error page

mod_shire/mod_shire.cpp
shib-target/shib-rpchandle.cpp

index 0bfc8cf..aea32ca 100644 (file)
@@ -451,7 +451,19 @@ extern "C" int shire_check_user(request_rec* r)
       session_id=cookiebuf;
 
       // Make sure this session is still valid
-      RPCError* status = shire.sessionIsValid(session_id, r->connection->remote_ip);
+      RPCError* status = NULL;
+
+      try {
+       status = shire.sessionIsValid(session_id, r->connection->remote_ip);
+
+      } catch (ShibTargetException &e) {
+       ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,r,
+                     "shire_check_user(): %s", e.what());
+       
+       markupProcessor.insert ("errorType", "SHIRE Processing Error");
+       markupProcessor.insert ("errorText", e.what());
+       return shire_error_page (r, wayfError.c_str(), markupProcessor);
+      }
 
       // Check the status
       if (status->isError()) {
index 512346b..e0be99f 100644 (file)
@@ -85,14 +85,29 @@ CLIENT * RPCHandle::connect(void)
 
   if (shib_sock_create (&sock) != 0) {
     m_priv->log->error ("Cannot create socket");
-    throw runtime_error ("Cannot create socket");
+    throw new ShibTargetException (-1, "Cannot create socket");
   }
 
-  // XXX: Loop until we connect?
-  if (shib_sock_connect (sock, m_priv->m_shar) != 0) {
-    m_priv->log->warn ("Cannot connect to SHAR");
+  bool connected = false;
+  int num_tries = 3;
+
+  for (int i = num_tries-1; i >= 0; i--) {
+    if (shib_sock_connect (sock, m_priv->m_shar) == 0) {
+      connected = tru;
+      break;
+    }
+
+    m_priv->log->warn ("Cannot connect to SHAR... %s",
+                       (i > 0 ? "retrying" : ""));
+
+    if (i)
+      sleep (2*(num_tries-i));
+  }
+
+  if (!connected) {
+    m_priv->log->crit ("SHAR Unavailable..  Failing.");
     close (sock);
-    throw runtime_error ("Cannot connect to SHAR");
+    throw new ShibTargetException (-1, "Cannot connect to SHAR");
   }
 
   CLIENT *clnt = shibrpc_client_create (sock, m_priv->m_program, m_priv->m_version);
@@ -100,7 +115,7 @@ CLIENT * RPCHandle::connect(void)
     const char * rpcerror = clnt_spcreateerror ("RPCHandle::connect");
     m_priv->log->error ("RPC failed: %s", rpcerror);
     close (sock);
-    throw runtime_error (rpcerror);
+    throw new ShibTargetException (-1, rpcerror);
   }
 
   m_priv->m_clnt = clnt;