diff options
-rw-r--r-- | src/c/urweb.c | 5 | ||||
-rw-r--r-- | src/mysql.sml | 28 |
2 files changed, 24 insertions, 9 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c index 9371147b..d656ae03 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -813,7 +813,7 @@ static void uw_try_reconnecting(uw_context ctx) { void uw_try_reconnecting_and_restarting(uw_context ctx) { uw_try_reconnecting(ctx); - uw_error(ctx, UNLIMITED_RETRY, "Restarting transaction after fixing database connection"); + uw_error(ctx, BOUNDED_RETRY, "Restarting transaction after fixing database connection"); } void uw_ensure_transaction(uw_context ctx) { @@ -826,7 +826,8 @@ void uw_ensure_transaction(uw_context ctx) { } ctx->transaction_started = 1; - } + } else if (ctx->at_most_one_query && !ctx->db) + uw_try_reconnecting(ctx); } uw_Basis_client uw_Basis_self(uw_context ctx) { diff --git a/src/mysql.sml b/src/mysql.sml index 057d73ff..692be0a2 100644 --- a/src/mysql.sml +++ b/src/mysql.sml @@ -861,11 +861,17 @@ fun queryCommon {loc, query, cols, doCols} = end) cols, newline, - string "if (mysql_stmt_reset(stmt)) uw_error(ctx, FATAL, \"", - string (ErrorMsg.spanToString loc), - string ": Error reseting statement: %s\\n%s\", ", - query, - string ", mysql_error(conn->conn));", + string "if (mysql_stmt_reset(stmt)) {", + box [newline, + string "if (mysql_errno(conn->conn) == 2006) uw_try_reconnecting_and_restarting(ctx);", + newline, + string "uw_error(ctx, FATAL, \"", + string (ErrorMsg.spanToString loc), + string ": Error reseting statement: %s\\n%s\", ", + query, + string ", mysql_error(conn->conn));", + newline], + string "}", newline, newline, @@ -1233,7 +1239,9 @@ fun queryPrepared {loc, id, query, inputs, cols, doCols, nested} = fun dmlCommon {loc, dml, mode} = box [string "if (mysql_stmt_execute(stmt)) {", - box [string "if (mysql_errno(conn->conn) == 1213)", + box [string "if (mysql_errno(conn->conn) == 2006) uw_try_reconnecting_and_restarting(ctx);", + newline, + string "if (mysql_errno(conn->conn) == 1213)", newline, box [string "uw_error(ctx, UNLIMITED_RETRY, \"Deadlock detected\");", newline], @@ -1540,7 +1548,13 @@ fun nextval {loc, seqE, seqName} = newline, newline, - string "if (mysql_query(conn->conn, insert)) uw_error(ctx, FATAL, \"'nextval' INSERT failed\");", + string "if (mysql_query(conn->conn, insert)) {", + box [newline, + string "if (mysql_errno(conn->conn) == 2006) uw_try_reconnecting_and_restarting(ctx);", + newline, + string "uw_error(ctx, FATAL, \"'nextval' INSERT failed\");", + newline], + string "}", newline, string "n = mysql_insert_id(conn->conn);", newline, |