comparison src/c/urweb.c @ 2000:bddee3af70c4

Tweaking uw_commit() logic, partly to fix a resource clean-up bug on SQL serialization failures
author Adam Chlipala <adam@chlipala.net>
date Tue, 15 Apr 2014 19:12:49 -0400
parents cc7e5d469d1b
children 16f5f136a807
comparison
equal deleted inserted replaced
1999:a1d3fbdcc897 2000:bddee3af70c4
3302 uw_rollback(ctx, 0); 3302 uw_rollback(ctx, 0);
3303 return 0; 3303 return 0;
3304 } 3304 }
3305 } 3305 }
3306 3306
3307 if (ctx->transaction_started) {
3308 int code = ctx->app->db_commit(ctx);
3309
3310 if (code) {
3311 if (ctx->client)
3312 release_client(ctx->client);
3313
3314 if (code == -1) {
3315 // This case is for a serialization failure, which is not really an "error."
3316 // The transaction will restart, so we should rollback any transactionals
3317 // that triggered above.
3318
3319 for (i = ctx->used_transactionals-1; i >= 0; --i)
3320 if (ctx->transactionals[i].rollback != NULL)
3321 ctx->transactionals[i].rollback(ctx->transactionals[i].data);
3322
3323 for (i = ctx->used_transactionals-1; i >= 0; --i)
3324 if (ctx->transactionals[i].free)
3325 ctx->transactionals[i].free(ctx->transactionals[i].data, 1);
3326
3327 return 1;
3328 }
3329
3330 for (i = ctx->used_transactionals-1; i >= 0; --i)
3331 if (ctx->transactionals[i].free)
3332 ctx->transactionals[i].free(ctx->transactionals[i].data, 0);
3333
3334 uw_set_error_message(ctx, "Error running SQL COMMIT");
3335 return 0;
3336 }
3337 }
3338
3307 for (i = ctx->used_transactionals-1; i >= 0; --i) 3339 for (i = ctx->used_transactionals-1; i >= 0; --i)
3308 if (ctx->transactionals[i].rollback == NULL) 3340 if (ctx->transactionals[i].rollback == NULL)
3309 if (ctx->transactionals[i].commit) { 3341 if (ctx->transactionals[i].commit) {
3310 ctx->transactionals[i].commit(ctx->transactionals[i].data); 3342 ctx->transactionals[i].commit(ctx->transactionals[i].data);
3311 if (uw_has_error(ctx)) { 3343 if (uw_has_error(ctx)) {
3312 uw_rollback(ctx, 0); 3344 if (ctx->client)
3345 release_client(ctx->client);
3346
3347 for (i = ctx->used_transactionals-1; i >= 0; --i)
3348 if (ctx->transactionals[i].rollback != NULL)
3349 ctx->transactionals[i].rollback(ctx->transactionals[i].data);
3350
3351 for (i = ctx->used_transactionals-1; i >= 0; --i)
3352 if (ctx->transactionals[i].free)
3353 ctx->transactionals[i].free(ctx->transactionals[i].data, 0);
3354
3313 return 0; 3355 return 0;
3314 } 3356 }
3315 } 3357 }
3316
3317 if (ctx->transaction_started) {
3318 int code = ctx->app->db_commit(ctx);
3319
3320 if (code) {
3321 if (code == -1)
3322 return 1;
3323
3324 for (i = ctx->used_transactionals-1; i >= 0; --i)
3325 if (ctx->transactionals[i].free)
3326 ctx->transactionals[i].free(ctx->transactionals[i].data, 0);
3327
3328 uw_set_error_message(ctx, "Error running SQL COMMIT");
3329 return 0;
3330 }
3331 }
3332 3358
3333 for (i = 0; i < ctx->used_deltas; ++i) { 3359 for (i = 0; i < ctx->used_deltas; ++i) {
3334 delta *d = &ctx->deltas[i]; 3360 delta *d = &ctx->deltas[i];
3335 client *c = find_client(d->client); 3361 client *c = find_client(d->client);
3336 3362