Skip to content

Commit e43e8ca

Browse files
authored
Always queue connectDestroyed() in loop. (#206)
1 parent 5586874 commit e43e8ca

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

trantor/net/TcpServer.cc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,15 @@ void TcpServer::handleCloseInLoop(const TcpConnectionPtr &connectionPtr)
168168
(void)n;
169169
assert(n == 1);
170170
auto connLoop = connectionPtr->getLoop();
171-
if (connLoop == loop_)
172-
{
171+
172+
// NOTE: always queue this operation in connLoop, because this connection
173+
// may be in loop_'s current active channels, waiting to be processed.
174+
// If `connectDestroyed()` is called here, we will be using an wild pointer
175+
// later.
176+
connLoop->queueInLoop([connectionPtr]() {
173177
static_cast<TcpConnectionImpl *>(connectionPtr.get())
174178
->connectDestroyed();
175-
}
176-
else
177-
{
178-
connLoop->queueInLoop([connectionPtr]() {
179-
static_cast<TcpConnectionImpl *>(connectionPtr.get())
180-
->connectDestroyed();
181-
});
182-
}
179+
});
183180
}
184181
void TcpServer::connectionClosed(const TcpConnectionPtr &connectionPtr)
185182
{

0 commit comments

Comments
 (0)