[cpp-sp] 02/02: Add retry logic to remoting service.

Codeberg noreply at shibboleth.net
Tue Nov 10 15:03:53 UTC 2026


This is an automated email from the git hooks/post-receive script.

codeberg pushed a commit to branch main
in repository cpp-sp.

View the commit online:
https://codeberg.org/Shibboleth/cpp-sp/commit/a82b8c04d442212c7ca04175a384c5e07f4662e4

commit a82b8c04d442212c7ca04175a384c5e07f4662e4
Author: Scott Cantor <scott at restingparrotsoftware.com>
AuthorDate: Tue Nov 10 10:03:18 2026 -0500

    Add retry logic to remoting service.
---
 .../remoting/impl/AbstractHTTPRemotingService.cpp  | 40 ++++++++++------------
 shibsp/remoting/impl/AbstractRemotingService.cpp   | 25 ++++++++++++--
 shibsp/remoting/impl/AbstractRemotingService.h     |  9 ++++-
 shibsp/remoting/impl/CurlHTTPRemotingService.cpp   |  4 +--
 shibsp/remoting/impl/WinHTTPRemotingService.cpp    |  2 --
 5 files changed, 50 insertions(+), 30 deletions(-)

diff --git a/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp b/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp
index 2d888921..6f1394e8 100644
--- a/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp
+++ b/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp
@@ -24,7 +24,6 @@
 #include "logging/Category.h"
 #include "remoting/SecretSource.h"
 #include "remoting/impl/AbstractHTTPRemotingService.h"
-#include "util/BoostPropertySet.h"
 #include "util/PathResolver.h"
 
 #include <sys/stat.h>
@@ -41,9 +40,6 @@ using namespace std;
 AbstractHTTPRemotingService::AbstractHTTPRemotingService(ptree& pt)
     : AbstractRemotingService(pt), m_authMethod(agent_auth_none), m_chunked(true)
 {
-    BoostPropertySet props;
-    props.load(pt);
-
     static const char AGENT_ID_PROP_NAME[] = "agentID";
     static const char SECRET_SOURCE_TYPE_PROP_NAME[] = "secretSourceType";
     static const char BASE_URL_PROP_NAME[] = "baseURL";
@@ -83,25 +79,25 @@ AbstractHTTPRemotingService::AbstractHTTPRemotingService(ptree& pt)
     static bool CHUNKED_PROP_DEFAULT = true;
     static const char TRACE_FILE_PROP_DEFAULT[] = "";
 
-    m_agentID = props.getString(AGENT_ID_PROP_NAME, AGENT_ID_PROP_DEFAULT);    
-    m_userAgent = props.getString(USER_AGENT_PROP_NAME, USER_AGENT_PROP_DEFAULT);
-    m_baseURL = props.getString(BASE_URL_PROP_NAME, BASE_URL_PROP_DEFAULT);
+    m_agentID = getString(AGENT_ID_PROP_NAME, AGENT_ID_PROP_DEFAULT);    
+    m_userAgent = getString(USER_AGENT_PROP_NAME, USER_AGENT_PROP_DEFAULT);
+    m_baseURL = getString(BASE_URL_PROP_NAME, BASE_URL_PROP_DEFAULT);
     if (m_baseURL.back() != '/') {
         m_baseURL += '/';
     }
 
-    m_authMethod = getAuthMethod(props.getString(AUTH_METHOD_PROP_NAME, AUTH_METHOD_PROP_DEFAULT));
-    m_connectTimeout = props.getUnsignedInt(CONNECT_TIMEOUT_PROP_NAME, CONNECT_TIMEOUT_PROP_DEFAULT);
-    m_timeout = props.getUnsignedInt(TIMEOUT_PROP_NAME, TIMEOUT_PROP_DEFAULT);
-    m_revocationCheck = props.getBool(REVOCATION_CHECK_PROP_NAME, REVOCATION_CHECK_DEFAULT);
-    m_enableIP4 = props.getBool(ENABLE_IP4_PROP_NAME, ENABLE_IP4_PROP_DEFAULT);
-    m_enableIP6 = props.getBool(ENABLE_IP6_PROP_NAME, ENABLE_IP6_PROP_DEFAULT);
-    m_chunked = props.getBool(CHUNKED_PROP_NAME, CHUNKED_PROP_DEFAULT);
-    m_disableTLS12 = props.getBool(DISABLE_TLS12_PROP_NAME, DISABLE_TLS12_PROP_DEFAULT);
-    m_disableTLS13 = props.getBool(DISABLE_TLS13_PROP_NAME, DISABLE_TLS13_PROP_DEFAULT);
-    m_tls12Ciphers = props.getString(TLS12_CIPHER_LIST_PROP_NAME, CIPHER_LIST_PROP_DEFAULT);
-    m_tls13Ciphers = props.getString(TLS13_CIPHER_LIST_PROP_NAME, CIPHER_LIST_PROP_DEFAULT);
-    m_traceFileBase = props.getString(TRACE_FILE_PROP_NAME, TRACE_FILE_PROP_DEFAULT);
+    m_authMethod = getAuthMethod(getString(AUTH_METHOD_PROP_NAME, AUTH_METHOD_PROP_DEFAULT));
+    m_connectTimeout = getUnsignedInt(CONNECT_TIMEOUT_PROP_NAME, CONNECT_TIMEOUT_PROP_DEFAULT);
+    m_timeout = getUnsignedInt(TIMEOUT_PROP_NAME, TIMEOUT_PROP_DEFAULT);
+    m_revocationCheck = getBool(REVOCATION_CHECK_PROP_NAME, REVOCATION_CHECK_DEFAULT);
+    m_enableIP4 = getBool(ENABLE_IP4_PROP_NAME, ENABLE_IP4_PROP_DEFAULT);
+    m_enableIP6 = getBool(ENABLE_IP6_PROP_NAME, ENABLE_IP6_PROP_DEFAULT);
+    m_chunked = getBool(CHUNKED_PROP_NAME, CHUNKED_PROP_DEFAULT);
+    m_disableTLS12 = getBool(DISABLE_TLS12_PROP_NAME, DISABLE_TLS12_PROP_DEFAULT);
+    m_disableTLS13 = getBool(DISABLE_TLS13_PROP_NAME, DISABLE_TLS13_PROP_DEFAULT);
+    m_tls12Ciphers = getString(TLS12_CIPHER_LIST_PROP_NAME, CIPHER_LIST_PROP_DEFAULT);
+    m_tls13Ciphers = getString(TLS13_CIPHER_LIST_PROP_NAME, CIPHER_LIST_PROP_DEFAULT);
+    m_traceFileBase = getString(TRACE_FILE_PROP_NAME, TRACE_FILE_PROP_DEFAULT);
 
     if (!m_enableIP4 && !m_enableIP6) {
         throw ConfigurationException("One of IP4 or IP6 must be enabled.");
@@ -113,11 +109,11 @@ AbstractHTTPRemotingService::AbstractHTTPRemotingService(ptree& pt)
 
     if (m_authMethod != agent_auth_none) {
         m_secretSource.reset(AgentConfig::getConfig().SecretSourceManager.newPlugin(
-            props.getString(SECRET_SOURCE_TYPE_PROP_NAME, SECRET_SOURCE_TYPE_PROP_DEFAULT), pt, false)
+            getString(SECRET_SOURCE_TYPE_PROP_NAME, SECRET_SOURCE_TYPE_PROP_DEFAULT), pt, false)
             );
     }
 
-    m_caFile = props.getString(CA_FILE_PROP_NAME, CA_FILE_PROP_DEFAULT);
+    m_caFile = getString(CA_FILE_PROP_NAME, CA_FILE_PROP_DEFAULT);
     if (!m_caFile.empty()) {
         AgentConfig::getConfig().getPathResolver().resolve(m_caFile, PathResolver::SHIBSP_CFG_FILE);
 #ifdef WIN32
@@ -136,7 +132,7 @@ AbstractHTTPRemotingService::AbstractHTTPRemotingService(ptree& pt)
         throw ConfigurationException("No tlsCAFile provided for https:// baseURL.");
     }
 
-    m_authCachingCookie = props.getString(AUTH_CACHING_COOKIE_PROP_NAME, AUTH_CACHING_COOKIE_PROP_DEFAULT);
+    m_authCachingCookie = getString(AUTH_CACHING_COOKIE_PROP_NAME, AUTH_CACHING_COOKIE_PROP_DEFAULT);
     if (!m_authCachingCookie.empty()) {
 #if defined(HAVE_CXX17)
         m_authcachelock.reset(new shared_mutex());
diff --git a/shibsp/remoting/impl/AbstractRemotingService.cpp b/shibsp/remoting/impl/AbstractRemotingService.cpp
index 5209e8e9..19e0dbbe 100644
--- a/shibsp/remoting/impl/AbstractRemotingService.cpp
+++ b/shibsp/remoting/impl/AbstractRemotingService.cpp
@@ -31,7 +31,15 @@ using namespace shibsp;
 using namespace boost::property_tree;
 using namespace std;
 
-AbstractRemotingService::AbstractRemotingService(const ptree&) {}
+AbstractRemotingService::AbstractRemotingService(const ptree& pt)
+        : m_log(Category::getInstance(SHIBSP_LOGCAT ".RemotingService")) {
+    load(pt);
+
+    static const char RETRIES_PROP_NAME[] = "retries";
+    static unsigned int RETRIES_PROP_DEFAULT = 2;
+
+    m_retries = getUnsignedInt(RETRIES_PROP_NAME, RETRIES_PROP_DEFAULT);
+}
 
 AbstractRemotingService::~AbstractRemotingService() {}
 
@@ -55,8 +63,21 @@ DDF AbstractRemotingService::send(const DDF& in, bool checkEvent) const
     stringstream instream;
     instream << in;
 
+    unsigned int retries = m_retries;
     stringstream outstream;
-    send(in.name(), instream, outstream);
+    while (true) {
+        try {
+            send(in.name(), instream, outstream);
+            break;
+        } catch (const RemotingException& ex) {
+            if (--retries) {
+                m_log.error("exception on call to Hub (retrying): %s", ex.what());
+            } else {
+                // No more retries.
+                throw ex;
+            }
+        }
+    };
 
     DDF output;
     outstream >> output;
diff --git a/shibsp/remoting/impl/AbstractRemotingService.h b/shibsp/remoting/impl/AbstractRemotingService.h
index 74a44cd2..d9c1be1a 100644
--- a/shibsp/remoting/impl/AbstractRemotingService.h
+++ b/shibsp/remoting/impl/AbstractRemotingService.h
@@ -23,6 +23,7 @@
 
 #include "remoting/RemotingService.h"
 #include "logging/Category.h"
+#include "util/BoostPropertySet.h"
 
 #include <iostream>
 #include <boost/property_tree/ptree_fwd.hpp>
@@ -32,7 +33,7 @@ namespace shibsp {
     /**
      * Base class for remoting services that handles data marshalling/unmarshalling.
      */
-    class SHIBSP_API AbstractRemotingService : public virtual RemotingService
+    class SHIBSP_API AbstractRemotingService : public virtual RemotingService, public virtual BoostPropertySet
     {
     public:
         virtual ~AbstractRemotingService();
@@ -52,6 +53,12 @@ namespace shibsp {
          * @param output output stream to capture response
          */
         virtual void send(const char* path, std::istream& input, std::ostream& output) const=0;
+
+    protected:
+        Category& m_log;
+
+    private:
+        unsigned int m_retries;
     };
 
 };
diff --git a/shibsp/remoting/impl/CurlHTTPRemotingService.cpp b/shibsp/remoting/impl/CurlHTTPRemotingService.cpp
index 4bcee051..ab2507ae 100644
--- a/shibsp/remoting/impl/CurlHTTPRemotingService.cpp
+++ b/shibsp/remoting/impl/CurlHTTPRemotingService.cpp
@@ -68,7 +68,6 @@ namespace {
         void attachCachedAuthentication(CURL* handle) const;
 
     private:
-        Category& m_log;
         bool m_curlInit;
         mutable list<CURL*> m_pool;
         mutable int m_poolsize;
@@ -162,8 +161,7 @@ namespace shibsp {
 CurlHTTPRemotingService::CurlHTTPRemotingService(ptree& pt) :
     AbstractRemotingService(pt),
     AbstractHTTPRemotingService(pt),
-    m_log(Category::getInstance(SHIBSP_LOGCAT ".RemotingService")),
-        m_curlInit(false), m_poolsize(20)
+    m_curlInit(false), m_poolsize(20)
 {
 
     CURLcode status = curl_global_init(CURL_GLOBAL_ALL);
diff --git a/shibsp/remoting/impl/WinHTTPRemotingService.cpp b/shibsp/remoting/impl/WinHTTPRemotingService.cpp
index 54b41573..04edb86d 100644
--- a/shibsp/remoting/impl/WinHTTPRemotingService.cpp
+++ b/shibsp/remoting/impl/WinHTTPRemotingService.cpp
@@ -70,7 +70,6 @@ namespace {
         void logSecureFailure(DWORD status) const;
 
     private:
-        Category& m_log;
         bool m_init;
         HINTERNET m_session;
         HINTERNET m_connection;
@@ -265,7 +264,6 @@ StatusCallback(
 WinHTTPRemotingService::WinHTTPRemotingService(ptree& pt)
     : AbstractRemotingService(pt),
     AbstractHTTPRemotingService(pt),
-    m_log(Category::getInstance(SHIBSP_LOGCAT ".RemotingService")),
     m_secure(false), m_caChainEngine(nullptr), m_caStore(nullptr),
     m_init(false)
 {

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list