diff src/c/urweb.c @ 1938:d02c1a0d8082

Proper handling of serialization failures during SQL COMMIT
author Adam Chlipala <adam@chlipala.net>
date Mon, 23 Dec 2013 15:59:17 +0000
parents 6745eafff617
children c52365a4ce41
line wrap: on
line diff
--- a/src/c/urweb.c	Tue Dec 17 20:12:33 2013 -0500
+++ b/src/c/urweb.c	Mon Dec 23 15:59:17 2013 +0000
@@ -3253,13 +3253,13 @@
   return s;
 }
 
-void uw_commit(uw_context ctx) {
+int uw_commit(uw_context ctx) {
   int i;
   char *sig;
 
   if (uw_has_error(ctx)) {
     uw_rollback(ctx, 0);
-    return;
+    return 0;
   }
 
   for (i = ctx->used_transactionals-1; i >= 0; --i)
@@ -3268,7 +3268,7 @@
         ctx->transactionals[i].commit(ctx->transactionals[i].data);
         if (uw_has_error(ctx)) {
           uw_rollback(ctx, 0);
-          return;
+          return 0;
         }
       }
 
@@ -3278,13 +3278,26 @@
         ctx->transactionals[i].commit(ctx->transactionals[i].data);
         if (uw_has_error(ctx)) {
           uw_rollback(ctx, 0);
-          return;
+          return 0;
         }
       }
 
-  if (ctx->transaction_started && ctx->app->db_commit(ctx)) {
-    uw_set_error_message(ctx, "Error running SQL COMMIT");
-    return;
+  if (ctx->transaction_started) {
+    int code =ctx->app->db_commit(ctx);
+
+    if (code) {
+      if (code == -1) {
+	uw_rollback(ctx, 1);
+	return 1;
+      }
+
+      for (i = ctx->used_transactionals-1; i >= 0; --i)
+	if (ctx->transactionals[i].free)
+	  ctx->transactionals[i].free(ctx->transactionals[i].data, 0);
+
+      uw_set_error_message(ctx, "Error running SQL COMMIT");
+      return 0;
+    }
   }
 
   for (i = 0; i < ctx->used_deltas; ++i) {
@@ -3390,6 +3403,8 @@
       } while (sig);
     }
   }
+
+  return 0;
 }