Skip to content

Commit

Permalink
Clean up all socket states when the socket is closed
Browse files Browse the repository at this point in the history
Reference: #7434
  • Loading branch information
teng-li committed May 17, 2018
1 parent 346b6c5 commit ba48f05
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions torch/lib/c10d/TCPStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,29 @@ void TCPStoreDaemon::run() {
// use the store. We will go ahead and close this connection whenever
// we hit an exception here.
::close(fds[fdIdx].fd);

// Remove all the tracking state of the close FD
for (auto it = waitingSockets_.begin(); it != waitingSockets_.end(); ) {
for (auto vecIt = it->second.begin(); vecIt != it->second.end(); ) {
if (*vecIt == fds[fdIdx].fd) {
vecIt = it->second.erase(vecIt);
} else {
++vecIt;
}
}
if (it->second.size() == 0) {
it = waitingSockets_.erase(it);
} else {
++it;
}
}
for (auto it = keysAwaited_.begin(); it != keysAwaited_.end(); ) {
if (it->first == fds[fdIdx].fd) {
it = keysAwaited_.erase(it);
} else {
++it;
}
}
fds.erase(fds.begin() + fdIdx);
sockets_.erase(sockets_.begin() + fdIdx - 2);
--fdIdx;
Expand Down

0 comments on commit ba48f05

Please sign in to comment.