You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2023/11/10 04:13:19 UTC

(logging-log4cxx) branch socket_appender_interrupt created (now d7f34509)

This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a change to branch socket_appender_interrupt
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


      at d7f34509 Prevent the SocketAppender connection monitor thread causing a deadlock on exit

This branch includes the following new commits:

     new d7f34509 Prevent the SocketAppender connection monitor thread causing a deadlock on exit

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(logging-log4cxx) 01/01: Prevent the SocketAppender connection monitor thread causing a deadlock on exit

Posted by sw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a commit to branch socket_appender_interrupt
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git

commit d7f34509ba64cf71980c2ce265fdae1d49805265
Author: Stephen Webb <sw...@gmail.com>
AuthorDate: Fri Nov 10 15:12:32 2023 +1100

    Prevent the SocketAppender connection monitor thread causing a deadlock on exit
---
 src/main/cpp/socketappenderskeleton.cpp | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/src/main/cpp/socketappenderskeleton.cpp b/src/main/cpp/socketappenderskeleton.cpp
index 32a985b0..677e811e 100644
--- a/src/main/cpp/socketappenderskeleton.cpp
+++ b/src/main/cpp/socketappenderskeleton.cpp
@@ -163,24 +163,20 @@ void SocketAppenderSkeleton::monitor()
 {
 	Pool p;
 	SocketPtr socket;
-	bool isClosed = _priv->closed;
 
-	while (!isClosed)
+	while (!is_closed())
 	{
 		try
 		{
-			if (!_priv->closed)
-			{
-				LogString msg(LOG4CXX_STR("Attempting connection to [")
-					+ _priv->address->toString() + LOG4CXX_STR(":"));
-				StringHelper::toString(_priv->port, p, msg);
-				msg += LOG4CXX_STR("].");
-				LogLog::debug(msg);
-				socket = Socket::create(_priv->address, _priv->port);
-				setSocket(socket, p);
-				LogLog::debug(LOG4CXX_STR("Connection established. Exiting connector thread."));
-				return;
-			}
+			LogString msg(LOG4CXX_STR("Attempting connection to [")
+				+ _priv->address->toString() + LOG4CXX_STR(":"));
+			StringHelper::toString(_priv->port, p, msg);
+			msg += LOG4CXX_STR("].");
+			LogLog::debug(msg);
+			socket = Socket::create(_priv->address, _priv->port);
+			setSocket(socket, p);
+			LogLog::debug(LOG4CXX_STR("Connection established. Exiting connector thread."));
+			return;
 		}
 		catch (ConnectException& e)
 		{
@@ -208,14 +204,11 @@ void SocketAppenderSkeleton::monitor()
 			LogLog::debug(msg);
 
 			std::unique_lock<std::mutex> lock( _priv->interrupt_mutex );
-			_priv->interrupt.wait_for( lock, std::chrono::milliseconds( _priv->reconnectionDelay ),
-				std::bind(&SocketAppenderSkeleton::is_closed, this) );
+			if (_priv->interrupt.wait_for( lock, std::chrono::milliseconds( _priv->reconnectionDelay ),
+				std::bind(&SocketAppenderSkeleton::is_closed, this) ))
+				break;
 		}
-
-		isClosed = _priv->closed;
 	}
-
-	LogLog::debug(LOG4CXX_STR("Exiting Connector.run() method."));
 }
 
 bool SocketAppenderSkeleton::is_closed()