fix: correctly clear after a request when an exception has been thrown

This commit is contained in:
Tomasz Sowa 2023-05-16 15:31:13 +02:00
parent dda325bbbf
commit 1655ae3562
Signed by: tomasz.sowa
GPG Key ID: 662CC1438638588B
1 changed files with 37 additions and 30 deletions

View File

@ -766,13 +766,28 @@ void App::ProcessRequestThrow()
void App::ProcessRequest() void App::ProcessRequest()
{ {
system.load_avg.StartRequest(cur.request);
log << log2 << config.log_delimiter << logend;
try try
{ {
system.load_avg.StartRequest(cur.request);
log << log2 << config.log_delimiter << logend;
ProcessRequestThrow(); ProcessRequestThrow();
}
catch(const std::exception & e)
{
log << log1 << "App: there was an exception: std::exception: " << e.what() << logend;
}
catch(const Error & e)
{
log << log1 << "App: there was an exception: Error: " << e << logend;
}
catch(...)
{
log << log1 << "App: there was an unknown exception" << logend;
}
try
{
if( cur.request->run_state == Request::RunState::normal_run ) if( cur.request->run_state == Request::RunState::normal_run )
{ {
cur.request->FinishRequest(); cur.request->FinishRequest();
@ -780,49 +795,41 @@ void App::ProcessRequest()
} }
SaveSessionsIfNeeded(); SaveSessionsIfNeeded();
}
catch(...)
{
log << log1 << "App: an exception when finishing a request" << logend;
}
try
{
if( cur.request->run_state == Request::RunState::finished ) if( cur.request->run_state == Request::RunState::finished )
{ {
ClearAfterRequest(); ClearAfterRequest();
} }
} }
catch(const std::exception & e)
{
log << log1 << "App: there was an exception: std::exception: " << e.what() << logend;
}
catch(const Error & e)
{
log << log1 << "App: there was an exception: Error: " << e << logend;
}
catch(...) catch(...)
{ {
log << log1 << "App: there was an unknown exception" << logend; log << log1 << "App: an exception when clearing after a request" << logend;
} }
} }
void App::ClearAfterRequest() void App::ClearAfterRequest()
{ {
try // simple operations which should not throw an exception
{ cur.request->Clear();
// simple operations which should not throw an exception cur.session->ClearAfterRequest();
cur.request->Clear(); cur.session = session_manager.GetTmpSession();
cur.session->ClearAfterRequest(); cur.mount = system.mounts.GetEmptyMount();
cur.session = session_manager.GetTmpSession(); system.mounts.pmount = cur.mount; // IMPROVE ME system.mounts.pmount will be removed
cur.mount = system.mounts.GetEmptyMount(); // send_data_buf doesn't have to be cleared and it is better to not clear it (optimizing)
system.mounts.pmount = cur.mount; // IMPROVE ME system.mounts.pmount will be removed
// send_data_buf doesn't have to be cleared and it is better to not clear it (optimizing)
model_connector.set_winix_request(nullptr); model_connector.set_winix_request(nullptr);
model_connector.set_winix_session(nullptr); model_connector.set_winix_session(nullptr);
model_connector.set_winix_session_logger(nullptr); model_connector.set_winix_session_logger(nullptr);
log << logendrequest; log << logendrequest;
}
catch(...)
{
log << log1 << "App: an exception when clearing after a request" << logend;
}
} }