nghttpx: Close listening socket on graceful shutdown

This commit is contained in:
Tatsuhiro Tsujikawa 2018-02-26 22:40:24 +09:00
parent 54573f28a8
commit 45d76cf501
4 changed files with 12 additions and 6 deletions

View File

@ -573,9 +573,14 @@ void signal_cb(struct ev_loop *loop, ev_signal *w, int revents) {
case EXEC_BINARY_SIGNAL:
exec_binary();
return;
case GRACEFUL_SHUTDOWN_SIGNAL:
case GRACEFUL_SHUTDOWN_SIGNAL: {
auto &listenerconf = get_config()->conn.listener;
for (auto &addr : listenerconf.addrs) {
close(addr.fd);
}
ipc_send(wp, SHRPX_IPC_GRACEFUL_SHUTDOWN);
return;
}
case RELOAD_SIGNAL:
reload_config(wp);
return;

View File

@ -452,6 +452,8 @@ void ConnectionHandler::add_acceptor(std::unique_ptr<AcceptHandler> h) {
acceptors_.push_back(std::move(h));
}
void ConnectionHandler::delete_acceptor() { acceptors_.clear(); }
void ConnectionHandler::enable_acceptor() {
for (auto &a : acceptors_) {
a->enable();

View File

@ -117,6 +117,7 @@ public:
struct ev_loop *get_loop() const;
Worker *get_single_worker() const;
void add_acceptor(std::unique_ptr<AcceptHandler> h);
void delete_acceptor();
void enable_acceptor();
void disable_acceptor();
void sleep_acceptor(ev_tstamp t);

View File

@ -114,12 +114,10 @@ void graceful_shutdown(ConnectionHandler *conn_handler) {
conn_handler->set_graceful_shutdown(true);
conn_handler->disable_acceptor();
// After disabling accepting new connection, dispatch incoming
// connection in backlog.
// TODO What happens for the connections not established in the
// kernel?
conn_handler->accept_pending_connection();
conn_handler->delete_acceptor();
conn_handler->graceful_shutdown_worker();