SSPCPP-656 - NameID insert logic appears wrong for ODBC Session store
[shibboleth/cpp-sp.git] / odbc-store / odbc-store.cpp
index 48bbe8e..9fea872 100644 (file)
@@ -332,8 +332,14 @@ ODBCStorageService::ODBCStorageService(const DOMElement* e) : m_log(Category::ge
     e = XMLHelper::getNextSiblingElement(e, RetryOnError);
     while (e) {
         if (e->hasChildNodes()) {
-            m_retries.push_back(XMLString::parseInt(e->getTextContent()));
-            m_log.info("will retry operations when native ODBC error (%ld) is returned", m_retries.back());
+            try {
+                int code = XMLString::parseInt(e->getTextContent());
+                m_retries.push_back(code);
+                m_log.info("will retry operations when native ODBC error (%d) is returned", code);
+            }
+            catch (XMLException&) {
+                m_log.error("skipping non-numeric ODBC retry code");
+            }
         }
         e = XMLHelper::getNextSiblingElement(e, RetryOnError);
     }
@@ -507,8 +513,15 @@ bool ODBCStorageService::createRow(const char* table, const char* context, const
         }
         m_log.error("insert record failed (t=%s, c=%s, k=%s)", table, context, key);
         logres = log_error(stmt, SQL_HANDLE_STMT, "23000");
-        if (logres.second)
-            return false;   // supposedly integrity violation?
+        if (logres.second) {
+            // Supposedly integrity violation.
+            // Try and delete any expired record still hanging around until the final attempt.
+            if (attempts > 0) {
+                reap(table, context);
+                continue;
+            }
+            return false;
+        }
     } while (attempts && logres.first);
 
     throw IOException("ODBC StorageService failed to insert record.");