cd8473cd35938a2831c33c2885434cccadcf0376
angie
  Tue Sep 10 11:57:53 2019 -0700
When re-saving a session, don't delete the session from namedSessionDb until & unless saveSessionData has completed without errAbort.  By deleting before saveSessionData, we were losing sessions when there was an errAbort condition.  refs #24119

diff --git src/hg/hgSession/hgSession.c src/hg/hgSession/hgSession.c
index 7eeeccf..1a61ba4 100644
--- src/hg/hgSession/hgSession.c
+++ src/hg/hgSession/hgSession.c
@@ -785,40 +785,40 @@
 char firstUseBuf[32];
 
 /* If this session already existed, preserve its firstUse and useCount. */
 sqlDyStringPrintf(dy, "SELECT firstUse, useCount FROM %s "
                   "WHERE userName = '%s' AND sessionName = '%s';",
                   namedSessionTable, encUserName, encSessionName);
 sr = sqlGetResult(conn, dy->string);
 if ((row = sqlNextRow(sr)) != NULL)
     {
     safef(firstUseBuf, sizeof(firstUseBuf), "'%s'", row[0]);
     firstUse = firstUseBuf;
     useCount = atoi(row[1]) + 1;
     }
 sqlFreeResult(&sr);
 
+saveSessionData(cart, encUserName, encSessionName,
+                cgiOptionalString(hgsSessionDataDbSuffix));
+
 /* Remove pre-existing session (if any) before updating. */
 dyStringClear(dy);
 sqlDyStringPrintf(dy, "DELETE FROM %s WHERE userName = '%s' AND "
                   "sessionName = '%s';",
                   namedSessionTable, encUserName, encSessionName);
 sqlUpdate(conn, dy->string);
 
-saveSessionData(cart, encUserName, encSessionName,
-                cgiOptionalString(hgsSessionDataDbSuffix));
-
 dyStringClear(dy);
 sqlDyStringPrintf(dy, "INSERT INTO %s ", namedSessionTable);
 dyStringAppend(dy, "(userName, sessionName, contents, shared, "
                "firstUse, lastUse, useCount, settings) VALUES (");
 dyStringPrintf(dy, "'%s', '%s', ", encUserName, encSessionName);
 dyStringAppend(dy, "'");
 cleanHgSessionFromCart(cart);
 struct dyString *encoded = newDyString(4096);
 cartEncodeState(cart, encoded);
 
 // Now add all the default visibilities to output.
 outDefaultTracks(cart, encoded);
 
 sqlDyAppendEscaped(dy, encoded->string);
 dyStringFree(&encoded);