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()
{
system.load_avg.StartRequest(cur.request);
log << log2 << config.log_delimiter << logend;
try
{
system.load_avg.StartRequest(cur.request);
log << log2 << config.log_delimiter << logend;
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 )
{
cur.request->FinishRequest();
@ -780,49 +795,41 @@ void App::ProcessRequest()
}
SaveSessionsIfNeeded();
}
catch(...)
{
log << log1 << "App: an exception when finishing a request" << logend;
}
try
{
if( cur.request->run_state == Request::RunState::finished )
{
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(...)
{
log << log1 << "App: there was an unknown exception" << logend;
log << log1 << "App: an exception when clearing after a request" << logend;
}
}
void App::ClearAfterRequest()
{
try
{
// simple operations which should not throw an exception
cur.request->Clear();
cur.session->ClearAfterRequest();
cur.session = session_manager.GetTmpSession();
cur.mount = system.mounts.GetEmptyMount();
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)
// simple operations which should not throw an exception
cur.request->Clear();
cur.session->ClearAfterRequest();
cur.session = session_manager.GetTmpSession();
cur.mount = system.mounts.GetEmptyMount();
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_session(nullptr);
model_connector.set_winix_session_logger(nullptr);
model_connector.set_winix_request(nullptr);
model_connector.set_winix_session(nullptr);
model_connector.set_winix_session_logger(nullptr);
log << logendrequest;
}
catch(...)
{
log << log1 << "App: an exception when clearing after a request" << logend;
}
log << logendrequest;
}