fix: connectionReader could access self in its destructor after it has already the object has already been deleted if an error can be thrown from connectionMonitor while still on the stack from scanPackets

This commit is contained in:
Evan Tschannen 2019-08-08 23:35:44 -07:00
parent 07f2dde0d5
commit 98b643b7ae
1 changed files with 4 additions and 0 deletions

View File

@ -417,6 +417,10 @@ struct Peer : NonCopyable {
}
}
//We cannot let an error be thrown from connectionMonitor while still on the stack from scanPackets in connectionReader
//because then it would not call the destructor of connectionReader when connectionReader is cancelled.
wait(delay(0));
if (peer->reliable.empty() && peer->unsent.empty()) {
if (peer->peerReferences == 0 &&
(peer->lastDataPacketSentTime < now() - FLOW_KNOBS->CONNECTION_MONITOR_UNREFERENCED_CLOSE_DELAY)) {