[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp
Henry Castro
hcastro at collabora.com
Wed Feb 3 21:00:58 UTC 2016
loolwsd/LOOLBroker.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)
New commits:
commit 58fa747bb421bdca9e431185b59dca916a6a3305
Author: Henry Castro <hcastro at collabora.com>
Date: Wed Feb 3 16:59:09 2016 -0400
loolwsd: avoid a broken lokit process block the loolbroker forever
diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index aa9d07a..d824eb7 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -574,6 +574,7 @@ static int createLibreOfficeKit(const bool sharePages,
{
Poco::UInt64 childPID;
int nFIFOWriter = -1;
+ int nFlags = O_WRONLY | O_NONBLOCK;
const std::string pipe = BROKER_PREFIX + std::to_string(childCounter++) + BROKER_SUFIX;
@@ -625,13 +626,55 @@ static int createLibreOfficeKit(const bool sharePages,
}
}
- if ( (nFIFOWriter = open(pipe.c_str(), O_WRONLY)) < 0 )
+ // open non-blocking to make sure that a broken lokit process will not
+ // block the loolbroker forever
+ {
+ short nRetries = 5;
+ std::mutex aFIFOMutex;
+ std::condition_variable aFIFOCV;
+ std::unique_lock<std::mutex> lock(aFIFOMutex);
+
+ while(nRetries && nFIFOWriter < 0)
+ {
+ aFIFOCV.wait_for(
+ lock,
+ std::chrono::microseconds(80000),
+ [&nFIFOWriter, &pipe, nFlags]
+ {
+ return (nFIFOWriter = open(pipe.c_str(), nFlags)) > 0;
+ });
+
+ if (nFIFOWriter < 0)
+ {
+ Log::debug("Retrying to establish pipe connection: " + std::to_string(nRetries));
+ }
+
+ --nRetries;
+ }
+ }
+
+ if (nFIFOWriter < 0)
{
Log::error("Error: failed to open write pipe [" + pipe + "] with kit. Abandoning child.");
ChildProcess(childPID, -1, -1);
return -1;
}
+ if ((nFlags = fcntl(nFIFOWriter, F_GETFL, 0)) < 0)
+ {
+ Log::error("Error: failed to get pipe flags [" + pipe + "].");
+ ChildProcess(childPID, -1, -1);
+ return -1;
+ }
+
+ nFlags &= ~O_NONBLOCK;
+ if (fcntl(nFIFOWriter, F_SETFL, nFlags) < 0)
+ {
+ Log::error("Error: failed to set pipe flags [" + pipe + "].");
+ ChildProcess(childPID, -1, -1);
+ return -1;
+ }
+
Log::info() << "Adding Kit #" << childCounter << ", PID: " << childPID << Log::end;
_childProcesses[childPID] = std::make_shared<ChildProcess>(childPID, -1, nFIFOWriter);
More information about the Libreoffice-commits
mailing list