c9f42961046e744998bbaf939cfd3e7a37fd117f
max
  Tue Oct 14 02:58:59 2025 -0700
changing how hgcentral connection is treated when an API key is supplied, open a connection and close it right afterwards, to make sure that no sleeping CGIs clog mysql connections, refs #36498

diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c
index 170c3c868a3..a2ba48fae6a 100644
--- src/hg/lib/hdb.c
+++ src/hg/lib/hdb.c
@@ -825,34 +825,37 @@
  * not specific to a particular genome lives.  Free this up
  * with hDisconnectCentral(). */
 {
 if (centralCc == NULL)
     hCentralMkCache();
 return sqlConnCacheAlloc(centralCc, centralDb);
 }
 
 void hDisconnectCentral(struct sqlConnection **pConn)
 /* Put back connection for reuse. */
 {
 if (*pConn != NULL)
     sqlConnCacheDealloc(centralCc, pConn);
 }
 
-void hFreeAllCentral() 
-/* disconnect and free all connections in the hgCentral connection cache */
+struct sqlConnection *hConnectCentralNoCache() 
+/* open an hgcentral connection, but do not use the cache. Used before the bottleneck call. */
 {
-    sqlConnCacheFree(&centralCc);
+    struct sqlConnection *conn = sqlMayConnect(centralDb);
+    if (conn == NULL)
+        errAbort("Cannot connect to MariaDB database defined in hg.conf called '%s'", centralDb);
+    return conn;
 }
 
 static void hCartMkCache()
 /* Create the cart connection cache.  Defaults to the central connection
  * unless cart.db or cart.host are configured. */
 {
 if ((cfgOption("cart.db") != NULL) || (cfgOption("cart.host") != NULL)
     || (cfgOption("cart.user") != NULL) || (cfgOption("cart.password") != NULL))
     {
     /* use explict cart options */
     cartDb = cfgOption("cart.db");
     if ((cartDb == NULL) || (cfgOption("cart.host") == NULL)
         || (cfgOption("cart.user") == NULL) || (cfgOption("cart.password") == NULL))
         errAbort("Must specify either all or none of the cart options in the hg.conf file.");
     cartCc = sqlConnCacheNewProfile("cart");