From 0b6b57f9acaa2ec648bf582ff67851331f8e6eef Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 14 Mar 2016 14:38:45 +0300 Subject: Use serializable transaction isolation level --- web/apache/service.txx | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'web/apache/service.txx') diff --git a/web/apache/service.txx b/web/apache/service.txx index b57befc..961c19b 100644 --- a/web/apache/service.txx +++ b/web/apache/service.txx @@ -3,9 +3,9 @@ // license : MIT; see accompanying LICENSE file #include // getppid() -#include // kill() +#include // kill(), SIGTERM -#include +#include // APLOG_* #include // move() #include @@ -132,21 +132,31 @@ namespace web const M* e (dynamic_cast (exemplar)); assert (e != nullptr); - M m (*e); - - if (static_cast (m).handle (rq, rq, lg)) - return rq.flush (); + for (M m (*e);;) + { + try + { + if (static_cast (m).handle (rq, rq, lg)) + return rq.flush (); - if (!rq.get_write_state ()) - return DECLINED; + if (rq.state () == request_state::initial) + return DECLINED; - lg.write (nullptr, 0, func_name.c_str (), APLOG_ERR, - "handling declined while unbuffered content " - "has been written"); + lg.write (nullptr, 0, func_name.c_str (), APLOG_ERR, + "handling declined being partially executed"); + break; + } + catch (const module::retry&) + { + // Retry to handle the request. + // + rq.rewind (); + } + } } catch (const invalid_request& e) { - if (!e.content.empty () && !rq.get_write_state ()) + if (!e.content.empty () && rq.state () < request_state::writing) { try { @@ -165,11 +175,12 @@ namespace web { lg.write (nullptr, 0, func_name.c_str (), APLOG_ERR, e.what ()); - if (*e.what () && !rq.get_write_state ()) + if (*e.what () && rq.state () < request_state::writing) { try { - rq.content (HTTP_INTERNAL_SERVER_ERROR, "text/plain;charset=utf-8") + rq.content ( + HTTP_INTERNAL_SERVER_ERROR, "text/plain;charset=utf-8") << e.what (); return rq.flush (); @@ -184,11 +195,12 @@ namespace web { lg.write (nullptr, 0, func_name.c_str (), APLOG_ERR, "unknown error"); - if (!rq.get_write_state ()) + if (rq.state () < request_state::writing) { try { - rq.content (HTTP_INTERNAL_SERVER_ERROR, "text/plain;charset=utf-8") + rq.content ( + HTTP_INTERNAL_SERVER_ERROR, "text/plain;charset=utf-8") << "unknown error"; return rq.flush (); -- cgit v1.1