fix(test): lock std:cerr to prevent data race in TCP server tests (reported by clang thread sanitizer) #4313

This commit is contained in:
Matej Kenda
2024-01-03 19:47:57 +01:00
parent 9a36adb979
commit 287befc4a3
3 changed files with 17 additions and 2 deletions

View File

@@ -18,6 +18,7 @@
#include "Poco/Net/StreamSocket.h"
#include "Poco/Net/ServerSocket.h"
#include "Poco/Thread.h"
#include "Poco/Mutex.h"
#include <iostream>
@@ -35,6 +36,8 @@ using Poco::Thread;
namespace
{
static Poco::FastMutex cerrMutex;
class EchoConnection: public TCPServerConnection
{
public:
@@ -55,8 +58,10 @@ namespace
n = ss.receiveBytes(buffer, sizeof(buffer));
}
}
catch (Poco::Exception& exc)
catch (const Poco::Exception& exc)
{
Poco::FastMutex::ScopedLock l(cerrMutex);
std::cerr << "EchoConnection: " << exc.displayText() << std::endl;
}
}