Mercurial > urweb
comparison src/c/urweb.c @ 2270:1e3ba868f8bf
Merge.
author | Ziv Scully <ziv@mit.edu> |
---|---|
date | Mon, 19 Oct 2015 14:42:22 -0400 |
parents | 34ad83d9b729 c76a9712334c |
children | b49d22a4eda8 |
comparison
equal
deleted
inserted
replaced
2269:f7bc7c11a656 | 2270:1e3ba868f8bf |
---|---|
807 ctx->app->handle(ctx, path); | 807 ctx->app->handle(ctx, path); |
808 | 808 |
809 return r; | 809 return r; |
810 } | 810 } |
811 | 811 |
812 static void uw_try_reconnecting(uw_context ctx) { | |
813 // Hm, error starting transaction. | |
814 // Maybe the database server died but has since come back up. | |
815 // Let's try starting from scratch. | |
816 if (ctx->db) { | |
817 ctx->app->db_close(ctx); | |
818 ctx->db = NULL; | |
819 } | |
820 ctx->app->db_init(ctx); | |
821 | |
822 if (!ctx->db) | |
823 uw_error(ctx, FATAL, "Error reopening database connection"); | |
824 } | |
825 | |
826 void uw_try_reconnecting_and_restarting(uw_context ctx) { | |
827 uw_try_reconnecting(ctx); | |
828 uw_error(ctx, BOUNDED_RETRY, "Restarting transaction after fixing database connection"); | |
829 } | |
830 | |
812 void uw_ensure_transaction(uw_context ctx) { | 831 void uw_ensure_transaction(uw_context ctx) { |
813 if (!ctx->transaction_started && !ctx->at_most_one_query) { | 832 if (!ctx->transaction_started && !ctx->at_most_one_query) { |
814 if (ctx->app->db_begin(ctx, ctx->could_write_db)) | 833 if (!ctx->db || ctx->app->db_begin(ctx, ctx->could_write_db)) { |
815 uw_error(ctx, BOUNDED_RETRY, "Error running SQL BEGIN"); | 834 uw_try_reconnecting(ctx); |
835 | |
836 if (ctx->app->db_begin(ctx, ctx->could_write_db)) | |
837 uw_error(ctx, FATAL, "Error running SQL BEGIN"); | |
838 } | |
839 | |
816 ctx->transaction_started = 1; | 840 ctx->transaction_started = 1; |
817 } | 841 } else if (ctx->at_most_one_query && !ctx->db) |
842 uw_try_reconnecting(ctx); | |
818 } | 843 } |
819 | 844 |
820 uw_Basis_client uw_Basis_self(uw_context ctx) { | 845 uw_Basis_client uw_Basis_self(uw_context ctx) { |
821 if (ctx->client == NULL) | 846 if (ctx->client == NULL) |
822 uw_error(ctx, FATAL, "Call to Basis.self() from page that has only server-side code"); | 847 uw_error(ctx, FATAL, "Call to Basis.self() from page that has only server-side code"); |