Bug #3222 » respawn.patch
src/fcgi/Server.C 2014-06-30 12:02:00.916205945 +0400 | ||
---|---|---|
Server::Server(WServer& wt, int argc, char *argv[])
|
||
: wt_(wt),
|
||
argc_(argc),
|
||
argv_(argv)
|
||
argv_(argv),
|
||
respawnCounter_(0)
|
||
{
|
||
instance = this;
|
||
... | ... | |
* TODO: cleanup all sessions that pointed to this pid
|
||
*/
|
||
static int childrenDied = 0;
|
||
++childrenDied;
|
||
if (childrenDied < 5)
|
||
spawnSharedProcess();
|
||
else
|
||
LOG_ERROR_S(&wt_, "sessions process restart limit (5) reached");
|
||
boost::mutex::scoped_lock lock(respawnMutex_);
|
||
respawnCounter_++;
|
||
respCv_.notify_one();
|
||
break;
|
||
}
|
||
... | ... | |
} else
|
||
LOG_INFO_S(&wt_, "reading FastCGI stream from stdin");
|
||
respawnMonitor_ = boost::thread(boost::bind(&Server::monitorRespawn, this));
|
||
wt_.ioService().start();
|
||
for (;;) {
|
||
... | ... | |
return 0;
|
||
}
|
||
void Server::monitorRespawn()
|
||
{
|
||
for (;;)
|
||
{
|
||
boost::mutex::scoped_lock lock(respawnMutex_);
|
||
while(respawnCounter_ == 0)
|
||
{
|
||
respCv_.wait(lock);
|
||
}
|
||
while (respawnCounter_ > 0)
|
||
{
|
||
LOG_INFO_S(&wt_, "respawn monitor: launching new session process...");
|
||
spawnSharedProcess();
|
||
respawnCounter_--;
|
||
}
|
||
}
|
||
}
|
||
void Server::handleRequestThreaded(int serverSocket)
|
||
{
|
||
#ifdef WT_THREADED
|
src/fcgi/Server.h 2014-06-30 12:01:04.519287618 +0400 | ||
---|---|---|
* For SharedProcess session policy
|
||
*/
|
||
std::vector<int> sessionProcessPids_;
|
||
volatile int respawnCounter_;
|
||
boost::thread respawnMonitor_;
|
||
boost::mutex respawnMutex_;
|
||
boost::condition_variable respCv_;
|
||
void monitorRespawn();
|
||
const std::string socketPath(const std::string& sessionId);
|
||
};
|