servercontext wait for transport worker threads to finish
doing this through Transport::close() causes deadlock in client code due to locking. So make this an extra step.
This commit is contained in:
@@ -1001,9 +1001,7 @@ bool AbstractCodec::directDeserialize(ByteBuffer *existingBuffer, char* deserial
|
||||
|
||||
BlockingTCPTransportCodec::~BlockingTCPTransportCodec()
|
||||
{
|
||||
assert(!_isOpen.get());
|
||||
_sendThread.exitWait();
|
||||
_readThread.exitWait();
|
||||
waitJoin();
|
||||
}
|
||||
|
||||
void BlockingTCPTransportCodec::readPollOne() {
|
||||
@@ -1035,6 +1033,13 @@ void BlockingTCPTransportCodec::close() {
|
||||
}
|
||||
}
|
||||
|
||||
void BlockingTCPTransportCodec::waitJoin()
|
||||
{
|
||||
assert(!_isOpen.get());
|
||||
_sendThread.exitWait();
|
||||
_readThread.exitWait();
|
||||
}
|
||||
|
||||
void BlockingTCPTransportCodec::internalClose(bool /*force*/)
|
||||
{
|
||||
this->internalDestroy();
|
||||
|
||||
@@ -317,6 +317,7 @@ public:
|
||||
virtual void scheduleSend() OVERRIDE FINAL {}
|
||||
virtual void sendCompleted() OVERRIDE FINAL {}
|
||||
virtual void close() OVERRIDE FINAL;
|
||||
virtual void waitJoin() OVERRIDE FINAL;
|
||||
virtual bool terminated() OVERRIDE FINAL;
|
||||
virtual bool isOpen() OVERRIDE FINAL;
|
||||
void start();
|
||||
|
||||
@@ -287,6 +287,9 @@ public:
|
||||
*/
|
||||
virtual void close() = 0;
|
||||
|
||||
//! Call after close() to wait for any worker threads to exit
|
||||
virtual void waitJoin() {}
|
||||
|
||||
/**
|
||||
* Check connection status.
|
||||
* @return <code>true</code> if connected.
|
||||
|
||||
@@ -375,6 +375,7 @@ void ServerContextImpl::destroyAllTransports()
|
||||
for (size_t i = 0; i < size; i++)
|
||||
{
|
||||
const Transport::shared_pointer& transport = transports[i];
|
||||
transport->waitJoin();
|
||||
if(!transport.unique())
|
||||
LOG(logLevelError, "Closed transport %s still has use_count=%u",
|
||||
transport->getRemoteName().c_str(),
|
||||
|
||||
Reference in New Issue
Block a user