diff --git a/include/seastar/net/posix-stack.hh b/include/seastar/net/posix-stack.hh index e76d7affaec..af80186e9f3 100644 --- a/include/seastar/net/posix-stack.hh +++ b/include/seastar/net/posix-stack.hh @@ -141,6 +141,7 @@ class posix_ap_server_socket_impl : public server_socket_impl { using sockets_map_t = std::unordered_map>; using conn_map_t = std::unordered_multimap; static thread_local sockets_map_t sockets; + friend class posix_network_stack; static thread_local conn_map_t conn_q; int _protocol; socket_address _sa; @@ -204,6 +205,7 @@ public: virtual bool has_per_core_namespace() override { return _reuseport; }; bool supports_ipv6() const override; std::vector network_interfaces() override; + virtual future<> initialize() override; }; class posix_ap_network_stack : public posix_network_stack { diff --git a/src/net/posix-stack.cc b/src/net/posix-stack.cc index 7a55b9fb8dc..ced3beb7a22 100644 --- a/src/net/posix-stack.cc +++ b/src/net/posix-stack.cc @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -96,6 +97,7 @@ class posix_connected_socket_operations { thread_local posix_ap_server_socket_impl::sockets_map_t posix_ap_server_socket_impl::sockets{}; thread_local posix_ap_server_socket_impl::conn_map_t posix_ap_server_socket_impl::conn_q{}; +static thread_local gate exiting_gate; class posix_tcp_connected_socket_operations : public posix_connected_socket_operations { public: @@ -498,9 +500,12 @@ posix_server_socket_impl::accept() { return make_ready_future( accept_result{connected_socket(std::move(csi)), sa}); } else { - // FIXME: future is discarded - (void)smp::submit_to(cpu, [protocol = _protocol, ssa = _sa, fd = std::move(fd.get_file_desc()), sa, cth = std::move(cth), allocator = _allocator] () mutable { - posix_ap_server_socket_impl::move_connected_socket(protocol, ssa, pollable_fd(std::move(fd)), sa, std::move(cth), allocator); + (void)with_gate(exiting_gate, [cpu, protocol = _protocol, ssa = _sa, fd = std::move(fd.get_file_desc()), sa, cth = std::move(cth), allocator = _allocator] () mutable { + return smp::submit_to(cpu, [protocol, ssa, fd = std::move(fd), sa, cth = std::move(cth), allocator] () mutable { + posix_ap_server_socket_impl::move_connected_socket(protocol, ssa, pollable_fd(std::move(fd)), sa, std::move(cth), allocator); + }); + }).handle_exception([] (const std::exception_ptr&) { + // intentionally ignored since we are exiting }); return accept(); } @@ -584,7 +589,7 @@ posix_ap_server_socket_impl::move_connected_socket(int protocol, socket_address i->second.set_exception(std::current_exception()); } sockets.erase(i); - } else { + } else if (!exiting_gate.is_closed()) { conn_q.emplace(std::piecewise_construct, std::make_tuple(t_sa), std::make_tuple(std::move(fd), std::move(addr), std::move(cth))); } } @@ -1093,6 +1098,15 @@ std::vector posix_network_stack::network_interfaces() { return std::vector(thread_local_interfaces.begin(), thread_local_interfaces.end()); } +future<> posix_network_stack::initialize() { + engine().at_exit([] { + return exiting_gate.close().then([] { + posix_ap_server_socket_impl::conn_q.clear(); + }); + }); + return make_ready_future<>(); +} + } }