From 93b1450e035189255cf44d27afafa1bc61d5c690 Mon Sep 17 00:00:00 2001 From: Francisco Date: Fri, 19 Feb 2021 19:51:56 +0000 Subject: [PATCH] fix enb crash during close down of enb and epc --- lib/include/srslte/common/network_utils.h | 3 ++- lib/src/common/network_utils.cc | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/include/srslte/common/network_utils.h b/lib/include/srslte/common/network_utils.h index 332938726..08466b592 100644 --- a/lib/include/srslte/common/network_utils.h +++ b/lib/include/srslte/common/network_utils.h @@ -147,7 +147,8 @@ private: cmd_id_t cmd = cmd_id_t::EXIT; int new_fd = -1; }; - bool remove_socket_unprotected(int fd, fd_set* total_fd_set, int* max_fd); + std::map::iterator + remove_socket_unprotected(int fd, fd_set* total_fd_set, int* max_fd); // args std::string name; diff --git a/lib/src/common/network_utils.cc b/lib/src/common/network_utils.cc index 4b795cf9b..4234b6e84 100644 --- a/lib/src/common/network_utils.cc +++ b/lib/src/common/network_utils.cc @@ -594,18 +594,20 @@ bool rx_multisocket_handler::remove_socket(int fd) return true; } -bool rx_multisocket_handler::remove_socket_unprotected(int fd, fd_set* total_fd_set, int* max_fd) +std::map::iterator +rx_multisocket_handler::remove_socket_unprotected(int fd, fd_set* total_fd_set, int* max_fd) { if (fd < 0) { rxSockError("fd to be removed is not valid"); - return false; + return active_sockets.end(); } - active_sockets.erase(fd); + auto it = active_sockets.find(fd); + it = active_sockets.erase(it); FD_CLR(fd, total_fd_set); // assumes ordering *max_fd = (active_sockets.empty()) ? pipefd[0] : std::max(pipefd[0], active_sockets.rbegin()->first); rxSockDebug("Socket fd=%d has been successfully removed", fd); - return true; + return it; } void rx_multisocket_handler::run_thread() @@ -636,16 +638,19 @@ void rx_multisocket_handler::run_thread() std::lock_guard lock(socket_mutex); // call read callback for all SCTP/TCP/UDP connections - for (auto& handler_pair : active_sockets) { - int fd = handler_pair.first; - recv_task* callback = handler_pair.second.get(); + for (auto handler_it = active_sockets.begin(); handler_it != active_sockets.end();) { + int fd = handler_it->first; + recv_task* callback = handler_it->second.get(); if (not FD_ISSET(fd, &read_fd_set)) { + ++handler_it; continue; } bool socket_valid = callback->operator()(fd); if (not socket_valid) { rxSockInfo("The socket fd=%d has been closed by peer", fd); - remove_socket_unprotected(fd, &total_fd_set, &max_fd); + handler_it = remove_socket_unprotected(fd, &total_fd_set, &max_fd); + } else { + ++handler_it; } }