Permalink
Browse files

Ozatomic found seg-faults on linux runs of eve-server.exe and I repea…

…ted those on windows for the latest commit. These crashes happen when you hit Ctrl+C in the server console to close it properly, then hit ENTER to finishe closing down the server. Randomly, you'll see the program crash. We strongly believe this was due to boost::asio threads left running when the server shutdown. Both ImageServer and APIServer use boost::asio threads for the TCP listeners. So, I implemented a public Stop() method in ImageServer and APIServer that issue a call to stop() of the _io object then join() the thread, blocking execution until the thread dies. Then these public Stop() methods are called in main.cpp AFTER the while {} loop so that when Ctrl+C is called, the while loop exits, these threads are killed and then the server shuts down. This seems to have fixed the issues on windows. Ozatomic will investigate the fix on linux.
  • Loading branch information...
aknorjaden committed Apr 23, 2012
1 parent 74ca97f commit d4ddda4db77b44665e9c43adb0f4247fe4742d35
@@ -58,6 +58,7 @@ class APIServer : public Singleton<APIServer>
public:
APIServer();
void Run();
+ void Stop();
void CreateServices(const PyServiceMgr &services);
std::string& url();
@@ -56,6 +56,7 @@ class ImageServer : public Singleton<ImageServer>
public:
ImageServer();
void Run();
+ void Stop();
std::string& url();
@@ -102,6 +102,12 @@ void APIServer::Run()
_ioThread = std::unique_ptr<asio::thread>(new asio::thread(std::tr1::bind(&APIServer::RunInternal, this)));
}
+void APIServer::Stop()
+{
+ _io->stop();
+ _ioThread->join();
+}
+
void APIServer::RunInternal()
{
_io = std::unique_ptr<asio::io_service>(new asio::io_service());
@@ -189,6 +189,12 @@ void ImageServer::Run()
_ioThread = std::auto_ptr<asio::thread>(new asio::thread(std::tr1::bind(&ImageServer::RunInternal, this)));
}
+void ImageServer::Stop()
+{
+ _io->stop();
+ _ioThread->join();
+}
+
void ImageServer::RunInternal()
{
_io = std::auto_ptr<asio::io_service>(new asio::io_service());
View
@@ -281,10 +281,18 @@ int main( int argc, char* argv[] )
sLog.Log("server shutdown", "Main loop stopped" );
+ // Shutting down EVE Client TCP listener
tcps.Close();
-
sLog.Log("server shutdown", "TCP listener stopped." );
+ // Shutting down API Server:
+ sAPIServer.Stop();
+ sLog.Log("server shutdown", "Image Server TCP listener stopped." );
+
+ // Shutting down Image Server:
+ sImageServer.Stop();
+ sLog.Log("server shutdown", "API Server TCP listener stopped." );
+
services.serviceDB().SetServerOnlineStatus(false);
sLog.Log("server shutdown", "Cleanup db cache" );
@@ -297,7 +305,7 @@ int main( int argc, char* argv[] )
// _CrtDumpMemoryLeaks();
//#endif /* defined( MSVC ) && !defined( NDEBUG ) */
- std::cout << std::endl << "press any key to exit..."; std::cin.get();
+ std::cout << std::endl << "press the ENTER key to exit..."; std::cin.get();
return 0;
}

0 comments on commit d4ddda4

Please sign in to comment.