Thread: [Cppcms-users] Shutdown issue
Brought to you by:
artyom-beilis
|
From: Sab <rim...@gm...> - 2013-03-14 09:03:38
|
Hallo Artyom,
I am running the cppcms::service in a separate thread. When the calling thread
restarts, I would also like to restart the cppcms service. On restart, I am
calling service.shutdown() from the main tread that executed it. I see the log
before the shutdown call but the log after the call is not printed -> I suspect
that the function hangs up because after the application exits the process still
keeps running in the background. This is my application’s main:
(Sorry for the code formatting...)
int main(int argc, char* argv[])
{
. . .
do
{
. . .
//start WebService
WebService webService(connector);
LOG_MAIN << "Starting the WebService thread";
boost::thread webServiceThread(webService);
. . .
while ( system.IsRunning() && !shutdownSignalReceived )
{
. . .
}
//stop WebService
LOG_MAIN << "Stopping WebService...";
webService.ShutDown();
webServiceThread.join();
. . .
}
while (runState == Common::Devices::Run::Reload);
}
------------------
My WebService class:
void WebService::operator()()
{
try
{
. . .
m_service = new cppcms::service(serviceConfig);
m_service->applications_pool().
mount(cppcms::applications_factory<MainWebHandler>
(m_connector));
m_service->run();
delete m_service;
}
catch(std::exception const &e)
{
LOG_MAIN_ERROR << "WebService exception: " << e.what();
}
}
void WebService::ShutDown()
{
try
{
cout << "Shutting down WebService..." << endl;
m_service->shutdown();
cout << "Shutting down WebService finished." << endl;
}
catch(std::exception const &e)
{
LOG_MAIN_ERROR << "WebService exception: " << e.what();
}
}
---------------
I don't get any error or exception. As mentioned I see the log “Shutting down
WebService...” but I don’t see “Shutting down WebService finished.” that’s why I
think the service doesn’t shut down properly so the thread keeps running in the
background.
Do you see anything wrong with my code?
Sab
|
|
From: Artyom B. <art...@ya...> - 2013-03-14 09:33:48
|
Few points: a) Enable this option: http://cppcms.com/wikipp/en/page/cppcms_1x_config#service.disable_global_exit_handling to prevent from the CppCMS service to install signal handlers. b) Put the log between m_service->run(); << Log exited delete m_service; To see if service exits. And probably put log after the delete to make sure that thread competes. Note the run() would not exit until all the worker threads had completed the job. c) Why don't you put cppcms::service on the stack such that it would not leak in case of exception... you code is not exception safe. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >________________________________ > From: Sab <rim...@gm...> >To: cpp...@li... >Sent: Thursday, March 14, 2013 11:03 AM >Subject: [Cppcms-users] Shutdown issue > >Hallo Artyom, > >I am running the cppcms::service in a separate thread. When the calling thread >restarts, I would also like to restart the cppcms service. On restart, I am >calling service.shutdown() from the main tread that executed it. I see the log >before the shutdown call but the log after the call is not printed -> I suspect >that the function hangs up because after the application exits the process still >keeps running in the background. This is my application’s main: > >(Sorry for the code formatting...) > >int main(int argc, char* argv[]) >{ >. . . >do >{ >. . . >//start WebService >WebService webService(connector); >LOG_MAIN << "Starting the WebService thread"; >boost::thread webServiceThread(webService); >. . . > >while ( system.IsRunning() && !shutdownSignalReceived ) >{ >. . . >} > >//stop WebService >LOG_MAIN << "Stopping WebService..."; >webService.ShutDown(); >webServiceThread.join(); >. . . >} >while (runState == Common::Devices::Run::Reload); >} > >------------------ >My WebService class: > >void WebService::operator()() >{ >try >{ >. . . >m_service = new cppcms::service(serviceConfig); >m_service->applications_pool(). >mount(cppcms::applications_factory<MainWebHandler> >(m_connector)); >m_service->run(); >delete m_service; >} >catch(std::exception const &e) >{ >LOG_MAIN_ERROR << "WebService exception: " << e.what(); >} >} > >void WebService::ShutDown() >{ >try >{ >cout << "Shutting down WebService..." << endl; >m_service->shutdown(); >cout << "Shutting down WebService finished." << endl; >} >catch(std::exception const &e) >{ >LOG_MAIN_ERROR << "WebService exception: " << e.what(); >} >} > >--------------- >I don't get any error or exception. As mentioned I see the log “Shutting down >WebService...” but I don’t see “Shutting down WebService finished.” that’s why I >think the service doesn’t shut down properly so the thread keeps running in the >background. > >Do you see anything wrong with my code? > >Sab > > > >------------------------------------------------------------------------------ >Everyone hates slow websites. So do we. >Make your web apps faster with AppDynamics >Download AppDynamics Lite for free today: >http://p.sf.net/sfu/appdyn_d2d_mar >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |
|
From: Artyom B. <art...@ya...> - 2013-03-23 15:03:20
|
Try to get the backtrace... It is hard to get what exactly happens there Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >________________________________ > From: Szabolcs Rimanóczy <rim...@go...> >To: Artyom Beilis <art...@ya...>; cpp...@li... >Sent: Thursday, March 14, 2013 7:56 PM >Subject: Re: [Cppcms-users] Shutdown issue > > >It's a bit better, now, it doesn't hang in the background but displays an error on exit. >This is what my application does: >- does something, >- reboots >- does something >- exits > > >When I set disable_global_exit_handling to false: > - on reboot: > - the last log is Shutting down WebService... (just before shutdown) > - no log is output between m_service->run(); and delete m_service; > - a log is output: "segfault at 0 ip 402744c0 sp bfaed3f0 error 4 in libcppcms.so.1.0.2[401f7000+211000]" > - on exit: > - log is output between m_service->run(); and delete m_service; > - the application never exits, stays in the background > > >When I set disable_global_exit_handling to true: > - on reboot: > - the last log is Shutting down WebService... (just before shutdown) > - no log is output between m_service->run(); and delete m_service; > - a log is output: "segfault at 0 ip 402744c0 sp bfbb16c0 error 4 in libcppcms.so.1.0.2[401f7000+211000]" > - on exit: > - the last log is Shutting down WebService... (just before shutdown) > - a log is output: "segfault at 0 ip 402744c0 sp bff07660 error 4 in libcppcms.so.1.0.2[401f7000+211000]" > > - the application doesn't hang in the background > - no log is output between m_service->run(); and delete m_service; > > >Any ideas what could be wrong? > > >Sab > > >2013/3/14 Artyom Beilis <art...@ya...> > >Few points: >> >> >>a) Enable this option: http://cppcms.com/wikipp/en/page/cppcms_1x_config#service.disable_global_exit_handling to prevent from the CppCMS service to install signal handlers. >> >> >>b) Put the log between >> >> >> m_service->run(); >> << Log exited >> delete m_service; >> >> >>To see if service exits. >> >> >>And probably put log after the delete to make sure that thread competes. >> >> >> >>Note the run() would not exit until all the worker threads had completed the job. >> >> >>c) Why don't you put cppcms::service on the stack such that it would not leak in case of exception... >> >>you code is not exception safe. >> >>Artyom Beilis >>-------------- >>CppCMS - C++ Web Framework: http://cppcms.com/ >>CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >> >> >> >>>________________________________ >>> From: Sab <rim...@gm...> >>>To: cpp...@li... >>>Sent: Thursday, March 14, 2013 11:03 AM >>>Subject: [Cppcms-users] Shutdown issue >>> >>> >>>Hallo Artyom, >>> >>>I am running the cppcms::service in a separate thread. When the calling thread >>>restarts, I would also like to restart the cppcms service. On restart, I am >>>calling service.shutdown() from the main tread that executed it. I see the log >>>before the shutdown call but the log after the call is not printed -> I suspect >>>that the function hangs up because after the application exits the process still >>>keeps running in the background. This is my application’s main: >>> >>>(Sorry for the code formatting...) >>> >>>int main(int argc, char* argv[]) >>>{ >>>. . . >>>do >>>{ >>>. . . >>>//start WebService >>>WebService webService(connector); >>>LOG_MAIN << "Starting the WebService thread"; >>>boost::thread webServiceThread(webService); >>>. . . >>> >>>while ( system.IsRunning() && !shutdownSignalReceived ) >>>{ >>>. . . >>>} >>> >>>//stop WebService >>>LOG_MAIN << "Stopping WebService..."; >>>webService.ShutDown(); >>>webServiceThread.join(); >>>. . . >>>} >>>while (runState == Common::Devices::Run::Reload); >>>} >>> >>>------------------ >>>My WebService class: >>> >>>void WebService::operator()() >>>{ >>>try >>>{ >>>. . . >>>m_service = new cppcms::service(serviceConfig); >>>m_service->applications_pool(). >>>mount(cppcms::applications_factory<MainWebHandler> >>>(m_connector)); >>>m_service->run(); >>>delete m_service; >>>} >>>catch(std::exception const &e) >>>{ >>>LOG_MAIN_ERROR << "WebService exception: " << e.what(); >>>} >>>} >>> >>>void WebService::ShutDown() >>>{ >>>try >>>{ >>>cout << "Shutting down WebService..." << endl; >>>m_service->shutdown(); >>>cout << "Shutting down WebService finished." << endl; >>>} >>>catch(std::exception const &e) >>>{ >>>LOG_MAIN_ERROR << "WebService exception: " << e.what(); >>>} >>>} >>> >>>--------------- >>>I don't get any error or exception. As mentioned I see the log “Shutting down >>>WebService...” but I don’t see “Shutting down WebService finished.” that’s why I >>>think the service doesn’t shut down properly so the thread keeps running in the >>>background. >>> >>>Do you see anything wrong with my code? >>> >>>Sab >>> >>> >>> >>>------------------------------------------------------------------------------ >>>Everyone hates slow websites. So do we. >>>Make your web apps faster with AppDynamics >>>Download AppDynamics Lite for free today: >>>http://p.sf.net/sfu/appdyn_d2d_mar >>>_______________________________________________ >>>Cppcms-users mailing list >>>Cpp...@li... >>>https://lists.sourceforge.net/lists/listinfo/cppcms-users >>> >>> >>> >>------------------------------------------------------------------------------ >>Everyone hates slow websites. So do we. >>Make your web apps faster with AppDynamics >>Download AppDynamics Lite for free today: >>http://p.sf.net/sfu/appdyn_d2d_mar >>_______________________________________________ >>Cppcms-users mailing list >>Cpp...@li... >>https://lists.sourceforge.net/lists/listinfo/cppcms-users >> >> > > > |