[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/LOOLWSD.cpp

2017-03-25 Thread Ashod Nakashian
 wsd/ClientSession.cpp |6 +++---
 wsd/LOOLWSD.cpp   |2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 1c5896f302befd2cede6098148d676cd678b91cf
Author: Ashod Nakashian 
Date:   Sun Mar 26 00:50:51 2017 -0400

wsd: count connections symmetrically

ClientSession::onDisconnect might not always be
called. The disymmetry between incrementing in
the ctor and decrementing in onDisconnect always
ran the risk of mismatch and leaking connection
counts, eventually blocking new clients.

Change-Id: I39ec65016984c0cddd0e16cfbf201049ced53713
Reviewed-on: https://gerrit.libreoffice.org/35713
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index fbc50b98..40d78f1d 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -47,7 +47,8 @@ ClientSession::ClientSession(const std::string& id,
 
 ClientSession::~ClientSession()
 {
-LOG_INF("~ClientSession dtor [" << getName() << "].");
+const size_t curConnections = --LOOLWSD::NumConnections;
+LOG_INF("~ClientSession dtor [" << getName() << "], current number of 
connections: " << curConnections);
 
 stop();
 }
@@ -726,8 +727,7 @@ bool ClientSession::forwardToClient(const 
std::shared_ptr& payload)
 
 void ClientSession::onDisconnect()
 {
-const size_t curConnections = --LOOLWSD::NumConnections;
-LOG_INF(getName() << " Disconnected, current # of connections: " << 
curConnections);
+LOG_INF(getName() << " Disconnected, current number of connections: " << 
LOOLWSD::NumConnections);
 
 const auto docBroker = getDocumentBroker();
 LOG_CHECK_RET(docBroker && "Null DocumentBroker instance", );
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index eaa02fcb..df3382a0 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1285,7 +1285,7 @@ static std::shared_ptr 
findOrCreateDocBroker(WebSocketHandler& w
 static_assert(MAX_DOCUMENTS > 0, "MAX_DOCUMENTS must be positive");
 if (DocBrokers.size() + 1 > MAX_DOCUMENTS)
 {
-LOG_ERR("Maximum number of open documents reached.");
+LOG_ERR("Maximum number of open documents of " << MAX_DOCUMENTS << 
" reached.");
 shutdownLimitReached(ws);
 return nullptr;
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/LOOLWSD.cpp

2017-03-16 Thread Ashod Nakashian
 wsd/ClientSession.cpp |8 +++-
 wsd/LOOLWSD.cpp   |   29 -
 2 files changed, 3 insertions(+), 34 deletions(-)

New commits:
commit f9664bb36981e34bf2e9f270bfc2bee7d65df36b
Author: Ashod Nakashian 
Date:   Wed Mar 15 10:45:42 2017 -0400

wsd: send recylcing message to clients on shutdown

Change-Id: Ibeb37b801e388fa33671a3c7df564c8ed86d9b71
Reviewed-on: https://gerrit.libreoffice.org/35306
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 64212a48..1f179ed4 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -736,11 +736,9 @@ void ClientSession::onDisconnect()
 }
 else
 {
-#if 0 // loolnb
-std::lock_guard lock(ClientWebSocketsMutex);
-LOG_TRC("Capturing Client WS for [" << _id << "]");
-// ClientWebSockets.push_back(ws); //FIXME
-#endif
+static const std::string msg("close: recycling");
+sendFrame(msg);
+shutdown(WebSocketHandler::StatusCodes::ENDPOINT_GOING_AWAY);
 }
 }
 catch (const std::exception& exc)
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index c12d7e60..fac23b22 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -179,12 +179,6 @@ static std::atomic OutstandingForks(0);
 static std::map DocBrokers;
 static std::mutex DocBrokersMutex;
 
-#if 0 // loolnb
-/// Used when shutting down to notify them all that the server is recycling.
-static std::vector ClientWebSockets;
-static std::mutex ClientWebSocketsMutex;
-#endif
-
 extern "C" { void dump_state(void); /* easy for gdb */ }
 
 #if ENABLE_DEBUG
@@ -2589,29 +2583,6 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 FileUtil::removeFile(path, true);
 }
 
-if (isShuttingDown())
-{
-#if 0 // loolnb
-// At this point there should be no other thread, but...
-std::lock_guard lock(ClientWebSocketsMutex);
-
-LOG_INF("Notifying clients that we are recycling.");
-static const std::string msg("close: recycling");
-for (auto& ws : ClientWebSockets)
-{
-try
-{
-ws->sendFrame(msg.data(), msg.size());
-ws->shutdown(WebSocket::WS_ENDPOINT_GOING_AWAY);
-}
-catch (const std::exception& ex)
-{
-LOG_ERR("Error while notifying client of recycle: " << 
ex.what());
-}
-}
-#endif
-}
-
 // Finally, we no longer need SSL.
 if (LOOLWSD::isSSLEnabled())
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/LOOLWSD.cpp

2017-03-16 Thread Jan Holesovsky
 wsd/ClientSession.cpp |6 --
 wsd/LOOLWSD.cpp   |   16 +---
 2 files changed, 5 insertions(+), 17 deletions(-)

New commits:
commit b384867b3fdf460b78917695b50d5ded8e99cc66
Author: Jan Holesovsky 
Date:   Thu Mar 16 11:33:35 2017 +0100

Fix limiting of the connections.

Change-Id: I9ff0aec168fd971599248fee177bf51b134e3e58

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 5ca126d..459754d 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -39,7 +39,8 @@ ClientSession::ClientSession(const std::string& id,
 _isDocumentOwner(false),
 _stop(false)
 {
-LOG_INF("ClientSession ctor [" << getName() << "].");
+const size_t curConnections = ++LOOLWSD::NumConnections;
+LOG_INF("ClientSession ctor [" << getName() << "], current number of 
connections: " << curConnections);
 }
 
 ClientSession::~ClientSession()
@@ -680,7 +681,8 @@ bool ClientSession::forwardToClient(const 
std::shared_ptr& payload)
 
 void ClientSession::onDisconnect()
 {
-LOG_INF(getName() << " Disconnected.");
+const size_t curConnections = --LOOLWSD::NumConnections;
+LOG_INF(getName() << " Disconnected, current # of connections: " << 
curConnections);
 
 const auto docBroker = getDocumentBroker();
 LOG_CHECK_RET(docBroker && "Null DocumentBroker instance", );
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index be63345..9c5fb00 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1718,22 +1718,9 @@ private:
 void onConnect(const std::weak_ptr& socket) override
 {
 _id = LOOLWSD::GenSessionId();
-_connectionNum = ++LOOLWSD::NumConnections;
-LOG_TRC("Connected connection #" << _connectionNum << " of " <<
-MAX_CONNECTIONS << " max as session [" << _id << "].");
-
 _socket = socket;
 }
 
-void onDisconnect() override
-{
-// FIXME: Move to ClientSession (ideally, wrap in ConnectionCounter 
object
-// to wrap this global NumConnections).
-const size_t curConnections = --LOOLWSD::NumConnections;
-LOG_TRC("Disconnected connection #" << _connectionNum << " (of " <<
-(curConnections + 1) << ") as session [" << _id << "].");
-}
-
 /// Called after successful socket reads.
 void handleIncomingMessage() override
 {
@@ -2215,7 +2202,7 @@ private:
 // First Upgrade.
 WebSocketHandler ws(_socket, request);
 
-if (_connectionNum > MAX_CONNECTIONS)
+if (LOOLWSD::NumConnections >= MAX_CONNECTIONS)
 {
 LOG_ERR("Limit on maximum number of connections of " << 
MAX_CONNECTIONS << " reached.");
 shutdownLimitReached(ws);
@@ -2279,7 +2266,6 @@ private:
 // The socket that owns us (we can't own it).
 std::weak_ptr _socket;
 std::string _id;
-size_t _connectionNum;
 };
 
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits