diff --git a/src/dpp/socketengine.cpp b/src/dpp/socketengine.cpp index bb611b5828..10301d4ec6 100644 --- a/src/dpp/socketengine.cpp +++ b/src/dpp/socketengine.cpp @@ -79,11 +79,15 @@ void socket_engine_base::prune() { to_delete_count = 0; } if (time(nullptr) != last_time) { - /* Every minute, rehash all cache containers. - * We do this from the socket engine now, not from - * shard 0, so no need to run shards to have timers! - */ - owner->tick_timers(); + try { + /* Every minute, rehash all cache containers. + * We do this from the socket engine now, not from + * shard 0, so no need to run shards to have timers! + */ + owner->tick_timers(); + } catch (const std::exception& e) { + owner->log(dpp::ll_error, "Uncaught exception in tick_timers: " + std::string(e.what())); + } if ((time(nullptr) % 60) == 0) { dpp::garbage_collection(); diff --git a/src/dpp/socketengines/epoll.cpp b/src/dpp/socketengines/epoll.cpp index 90d4ed11a3..77b2b34c71 100644 --- a/src/dpp/socketengines/epoll.cpp +++ b/src/dpp/socketengines/epoll.cpp @@ -90,36 +90,42 @@ struct socket_engine_epoll : public socket_engine_base { continue; } - if ((ev.events & EPOLLHUP) != 0U) { - if (eh->on_error) { - eh->on_error(fd, *eh, EPIPE); - } - continue; - } + try { - if ((ev.events & EPOLLERR) != 0U) { - socklen_t codesize = sizeof(int); - int errcode{}; - if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &errcode, &codesize) < 0) { - errcode = errno; + if ((ev.events & EPOLLHUP) != 0U) { + if (eh->on_error) { + eh->on_error(fd, *eh, EPIPE); + } + continue; } - if (eh->on_error) { - eh->on_error(fd, *eh, errcode); + + if ((ev.events & EPOLLERR) != 0U) { + socklen_t codesize = sizeof(int); + int errcode{}; + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &errcode, &codesize) < 0) { + errcode = errno; + } + if (eh->on_error) { + eh->on_error(fd, *eh, errcode); + } + continue; } - continue; - } - if ((ev.events & EPOLLOUT) != 0U) { - eh->flags = modify_event(epoll_handle, eh, eh->flags & ~WANT_WRITE); - if (eh->on_write) { - eh->on_write(fd, *eh); + if ((ev.events & EPOLLOUT) != 0U) { + eh->flags = modify_event(epoll_handle, eh, eh->flags & ~WANT_WRITE); + if (eh->on_write) { + eh->on_write(fd, *eh); + } } - } - if ((ev.events & EPOLLIN) != 0U) { - if (eh->on_read) { - eh->on_read(fd, *eh); + if ((ev.events & EPOLLIN) != 0U) { + if (eh->on_read) { + eh->on_read(fd, *eh); + } } + + } catch (const std::exception& e) { + eh->on_error(fd, *eh, 0); } } prune(); diff --git a/src/dpp/socketengines/kqueue.cpp b/src/dpp/socketengines/kqueue.cpp index dda636b145..0f162d3fc1 100644 --- a/src/dpp/socketengines/kqueue.cpp +++ b/src/dpp/socketengines/kqueue.cpp @@ -69,24 +69,30 @@ struct socket_engine_kqueue : public socket_engine_base { continue; } - const short filter = kev.filter; - if (kev.flags & EV_EOF || kev.flags & EV_ERROR) { - if (eh->on_error) { - eh->on_error(kev.ident, *eh, kev.fflags); + try { + + const short filter = kev.filter; + if (kev.flags & EV_EOF || kev.flags & EV_ERROR) { + if (eh->on_error) { + eh->on_error(kev.ident, *eh, kev.fflags); + } + continue; } - continue; - } - if (filter == EVFILT_WRITE) { - const int bits_to_clr = WANT_WRITE; - eh->flags &= ~bits_to_clr; - if (eh->on_write) { - eh->on_write(kev.ident, *eh); + if (filter == EVFILT_WRITE) { + const int bits_to_clr = WANT_WRITE; + eh->flags &= ~bits_to_clr; + if (eh->on_write) { + eh->on_write(kev.ident, *eh); + } } - } - else if (filter == EVFILT_READ) { - if (eh->on_read) { - eh->on_read(kev.ident, *eh); + else if (filter == EVFILT_READ) { + if (eh->on_read) { + eh->on_read(kev.ident, *eh); + } } + + } catch (const std::exception& e) { + eh->on_error(kev.ident, *eh, 0); } } prune(); diff --git a/src/dpp/socketengines/poll.cpp b/src/dpp/socketengines/poll.cpp index f0dd308b85..197fdf6640 100644 --- a/src/dpp/socketengines/poll.cpp +++ b/src/dpp/socketengines/poll.cpp @@ -73,30 +73,36 @@ struct socket_engine_poll : public socket_engine_base { } socket_events* eh = iter->second.get(); - if ((revents & POLLHUP) != 0) { - eh->on_error(fd, *eh, 0); - continue; - } + try { - if ((revents & POLLERR) != 0) { - socklen_t codesize = sizeof(int); - int errcode{}; - if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*)&errcode, &codesize) < 0) { - errcode = errno; + if ((revents & POLLHUP) != 0) { + eh->on_error(fd, *eh, 0); + continue; } - eh->on_error(fd, *eh, errcode); - continue; - } - if ((revents & POLLIN) != 0) { - eh->on_read(fd, *eh); - } + if ((revents & POLLERR) != 0) { + socklen_t codesize = sizeof(int); + int errcode{}; + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*)&errcode, &codesize) < 0) { + errcode = errno; + } + eh->on_error(fd, *eh, errcode); + continue; + } + + if ((revents & POLLIN) != 0) { + eh->on_read(fd, *eh); + } - if ((revents & POLLOUT) != 0) { - int mask = eh->flags; - mask &= ~WANT_WRITE; - eh->flags = mask; - eh->on_write(fd, *eh); + if ((revents & POLLOUT) != 0) { + int mask = eh->flags; + mask &= ~WANT_WRITE; + eh->flags = mask; + eh->on_write(fd, *eh); + } + + } catch (const std::exception& e) { + eh->on_error(fd, *eh, 0); } } prune(); diff --git a/src/dpp/sslclient.cpp b/src/dpp/sslclient.cpp index 3e9d24862b..c13dc70db3 100644 --- a/src/dpp/sslclient.cpp +++ b/src/dpp/sslclient.cpp @@ -483,7 +483,9 @@ void ssl_client::on_write(socket fd, const struct socket_events& e) { } void ssl_client::on_error(socket fd, const struct socket_events&, int error_code) { - throw dpp::connection_exception(err_socket_error, strerror(errno)); + if (sfd != INVALID_SOCKET) { + this->close(); + } } void ssl_client::read_loop()