From: Timo Sirainen Date: Wed, 23 Oct 2013 13:10:30 +0000 (+0300) Subject: lib-master: If service_count=1, close the listener before starting to handle the... X-Git-Tag: 2.2.7~56 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9217d2426b4f8ece47441357f35d8bb34d97c4eb;p=thirdparty%2Fdovecot%2Fcore.git lib-master: If service_count=1, close the listener before starting to handle the connection. This way if the connection handling takes a long time and the service doesn't notice that master dies, it can keep running without keeping the listener fds open and preventing a restart. --- diff --git a/src/lib-master/master-service.c b/src/lib-master/master-service.c index 476b37d07d..264690e0fb 100644 --- a/src/lib-master/master-service.c +++ b/src/lib-master/master-service.c @@ -638,6 +638,15 @@ void master_service_client_connection_created(struct master_service *service) i_assert(service->master_status.available_count > 0); service->master_status.available_count--; master_status_update(service); + + if (service->master_status.available_count == 0 && + service->service_count_left == 1) { + /* we're not going to accept any more connections after this. + go ahead and close the connection early. */ + i_assert(service->listeners != NULL); + master_service_io_listeners_remove(service); + master_service_io_listeners_close(service); + } } void master_service_client_connection_accept(struct master_service_connection *conn) @@ -923,6 +932,7 @@ static void master_service_io_listeners_close(struct master_service *service) i_error("close(listener %d) failed: %m", service->listeners[i].fd); } + service->listeners[i].fd = -1; } } } else {