Skip to content

Commit b0dc9c5

Browse files
authored
fix(SocketReactorTest): deadlock test intermittently hangs pocoproject#4400 (pocoproject#4401)
1 parent 9f4b1b7 commit b0dc9c5

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

Diff for: Net/src/SocketReactor.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Poco {
2727
namespace Net {
2828

2929

30-
SocketReactor::SocketReactor():
30+
SocketReactor::SocketReactor(): _threadAffinity(-1),
3131
_stop(false),
3232
_pReadableNotification(new ReadableNotification(this)),
3333
_pWritableNotification(new WritableNotification(this)),
@@ -86,6 +86,7 @@ void SocketReactor::run()
8686
if (hasSocketHandlers())
8787
{
8888
sm = _pollSet.poll(_params.pollTimeout);
89+
if (_stop) break;
8990
for (const auto& s : sm)
9091
{
9192
try
@@ -167,7 +168,6 @@ void SocketReactor::stop()
167168

168169
void SocketReactor::wakeUp()
169170
{
170-
if (_stop) return;
171171
_pollSet.wakeUp();
172172
_event.set();
173173
}

Diff for: Net/testsuite/src/SocketReactorTest.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,14 @@ namespace
416416
void onReadable(ReadableNotification* pNf)
417417
{
418418
pNf->release();
419-
char buffer[64];
420-
do
419+
std::vector<char> buffer;
420+
int n = 0;
421+
while ((n = _socket.available()))
421422
{
422-
if (0 == _socket.receiveBytes(&buffer[0], sizeof(buffer)))
423-
break;
424-
} while (true);
423+
if (n > buffer.size()) buffer.resize(n);
424+
n = _socket.receiveBytes(&buffer[0], buffer.size());
425+
if (0 == n) break;
426+
}
425427
}
426428

427429
void onShutdown(ShutdownNotification* pNf)

Diff for: cppignore.win

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class CppUnit::TestCaller<class RawSocketTest>.testEchoIPv4Move
66
class CppUnit::TestCaller<class ICMPClientTest>.testPing
77
class CppUnit::TestCaller<class ICMPClientTest>.testBigPing
88
class CppUnit::TestCaller<class HTTPSClientSessionTest>.testProxy
9-
class CppUnit::TestCaller<class HTTPSStreamFactoryTest>.testProxy
9+
class CppUnit::TestCaller<class HTTPSStreamFactoryTest>.testProxy
1010
class CppUnit::TestCaller<class TCPServerTest>.testReuseSocket
1111
class CppUnit::TestCaller<class HTTPSClientSessionTest>.testInterop
1212
class CppUnit::TestCaller<class PathTest>.testFind
@@ -21,4 +21,3 @@ class CppUnit::TestCaller<class WinServiceTest>.testServiceReturnsTrueIfStopped
2121
class CppUnit::TestCaller<class ICMPSocketTest>.testSendToReceiveFrom
2222
class CppUnit::TestCaller<class ICMPSocketTest>.testMTU
2323
class CppUnit::TestCaller<class HTTPSClientSessionTest>.testCachedSession
24-
class CppUnit::TestCaller<class PollSetTest>.testPollClosedServer

0 commit comments

Comments
 (0)