df74105539e5849345e7b6d6ccc18c4e0295d5f9
chmalee
  Mon Jun 9 14:02:06 2025 -0700
Fix bug during a refactoring that caused us to try detaching from a thread that was off the end of the thread array. This makes track search on hubs work again, refs #35807

diff --git src/hg/hgTracks/searchTracks.c src/hg/hgTracks/searchTracks.c
index b1880447e55..899e6fe954b 100644
--- src/hg/hgTracks/searchTracks.c
+++ src/hg/hgTracks/searchTracks.c
@@ -493,35 +493,35 @@
     int ptMax = atoi(cfgOptionDefault("parallelFetch.threads", "20"));
     int pfdListCount = 0, pt;
     if (ptMax > 0)
         {
         pfdListCount = slCount(pfdList);
         pthread_t *threads = NULL;
         ptMax = min(ptMax, pfdListCount);
         if (ptMax > 0)
             {
             AllocArray(threads, ptMax);
             for (pt = 0; pt < ptMax; pt++)
                 {
                 int rc = pthread_create(&threads[pt], NULL, addUnconnectedHubSearchResults, NULL);
                 if (rc )
                     errAbort("Unexpected error in pthread_create");
-                }
                 pthread_detach(threads[pt]);
                 // this thread will just happily keep working until waitForSearchResults() finishes,
                 // moving it's completed work onto pfdDone, so we can safely detach
                 }
+            }
         waitForSearchResults(ptMax, threads);
         }
     }
 if (measureTiming)
     measureTime("Total time spent searching hubs");
 }
 
 static void simpleSearchForTracks(char *simpleEntry)
 // Performs the simple search and returns the found tracks.
 {
 // Prepare for trix search
 if (!isEmpty(simpleEntry))
     {
     int trixWordCount = 0;
     char *tmp = cloneString(simpleEntry);