ext/common/agents/HelperAgent/Main.cpp in passenger-5.0.8 vs ext/common/agents/HelperAgent/Main.cpp in passenger-5.0.9

- old
+ new

@@ -157,10 +157,25 @@ for (unsigned int i = 0; i < SERVER_KIT_MAX_SERVER_ENDPOINTS; i++) { serverFds[i] = -1; adminServerFds[i] = -1; } } + + ~WorkingObjects() { + delete prestarterThread; + + vector<ThreadWorkingObjects>::iterator it, end = threadWorkingObjects.end(); + for (it = threadWorkingObjects.begin(); it != end; it++) { + delete it->requestHandler; + delete it->serverKitContext; + delete it->bgloop; + } + + delete adminWorkingObjects.adminServer; + delete adminWorkingObjects.serverKitContext; + delete adminWorkingObjects.bgloop; + } }; } // namespace ServerAgent } // namespace Passenger using namespace Passenger::ServerAgent; @@ -578,15 +593,16 @@ ThreadWorkingObjects two; if (i == 0) { two.bgloop = firstLoop = new BackgroundEventLoop(true, true); } else { - two.bgloop = new BackgroundEventLoop(true, false); + two.bgloop = new BackgroundEventLoop(true, true); } UPDATE_TRACE_POINT(); - two.serverKitContext = new ServerKit::Context(two.bgloop->safe); + two.serverKitContext = new ServerKit::Context(two.bgloop->safe, + two.bgloop->libuv_loop); two.serverKitContext->secureModePassword = wo->password; two.serverKitContext->defaultFileBufferedChannelConfig.bufferDir = options.get("data_buffer_dir"); two.serverKitContext->defaultFileBufferedChannelConfig.threshold = options.getUint("file_buffer_threshold"); @@ -605,30 +621,29 @@ wo->threadWorkingObjects.push_back(two); } UPDATE_TRACE_POINT(); ev_signal_init(&wo->sigquitWatcher, printInfo, SIGQUIT); - ev_signal_start(firstLoop->loop, &wo->sigquitWatcher); + ev_signal_start(firstLoop->libev_loop, &wo->sigquitWatcher); ev_signal_init(&wo->sigintWatcher, onTerminationSignal, SIGINT); - ev_signal_start(firstLoop->loop, &wo->sigintWatcher); + ev_signal_start(firstLoop->libev_loop, &wo->sigintWatcher); ev_signal_init(&wo->sigtermWatcher, onTerminationSignal, SIGTERM); - ev_signal_start(firstLoop->loop, &wo->sigtermWatcher); + ev_signal_start(firstLoop->libev_loop, &wo->sigtermWatcher); UPDATE_TRACE_POINT(); if (!adminAddresses.empty()) { UPDATE_TRACE_POINT(); AdminWorkingObjects *awo = &wo->adminWorkingObjects; - awo->bgloop = new BackgroundEventLoop(true, false); - awo->serverKitContext = new ServerKit::Context(awo->bgloop->safe); + awo->bgloop = new BackgroundEventLoop(true, true); + awo->serverKitContext = new ServerKit::Context(awo->bgloop->safe, + awo->bgloop->libuv_loop); awo->serverKitContext->secureModePassword = wo->password; - // Configure a large threshold so that it uses libeio as little as possible. - // libeio runs on the RequestHandler's first thread, and if there's a - // problem there we don't want it to affect the admin server. - awo->serverKitContext->defaultFileBufferedChannelConfig.threshold = 1024 * 1024; awo->serverKitContext->defaultFileBufferedChannelConfig.bufferDir = options.get("data_buffer_dir"); + awo->serverKitContext->defaultFileBufferedChannelConfig.threshold = + options.getUint("file_buffer_threshold"); UPDATE_TRACE_POINT(); awo->adminServer = new ServerAgent::AdminServer(awo->serverKitContext); awo->adminServer->requestHandlers.reserve(wo->threadWorkingObjects.size()); for (unsigned int i = 0; i < wo->threadWorkingObjects.size(); i++) { @@ -910,24 +925,28 @@ } wo->appPool.reset(); for (unsigned i = 0; i < wo->threadWorkingObjects.size(); i++) { ThreadWorkingObjects *two = &wo->threadWorkingObjects[i]; delete two->requestHandler; + two->requestHandler = NULL; } if (wo->prestarterThread != NULL) { wo->prestarterThread->interrupt_and_join(); delete wo->prestarterThread; + wo->prestarterThread = NULL; } for (unsigned int i = 0; i < SERVER_KIT_MAX_SERVER_ENDPOINTS; i++) { if (wo->serverFds[i] != -1) { close(wo->serverFds[i]); } if (wo->adminServerFds[i] != -1) { close(wo->adminServerFds[i]); } } deletePidFile(); + delete workingObjects; + workingObjects = NULL; P_NOTICE(AGENT_EXE " server shutdown finished"); } static void deletePidFile() { @@ -958,10 +977,12 @@ mainLoop(); UPDATE_TRACE_POINT(); cleanup(); } catch (const tracable_exception &e) { + // We intentionally don't call cleanup() in + // order to avoid various destructor assertions. P_CRITICAL("ERROR: " << e.what() << "\n" << e.backtrace()); deletePidFile(); return 1; } @@ -1168,12 +1189,16 @@ } } int serverMain(int argc, char *argv[]) { + int ret; + agentsOptions = new VariantMap(); *agentsOptions = initializeAgent(argc, &argv, AGENT_EXE " server", parseOptions, preinitialize, 2); setAgentsOptionsDefaults(); sanityCheckOptions(); - return runServer(); + ret = runServer(); + shutdownAgent(agentsOptions); + return ret; }