]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-master: If service_count=1, close the listener before starting to handle the...
authorTimo Sirainen <tss@iki.fi>
Wed, 23 Oct 2013 13:10:30 +0000 (16:10 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 23 Oct 2013 13:10:30 +0000 (16:10 +0300)
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.

src/lib-master/master-service.c

index 476b37d07d2de4e953f6f3b8513eab216f502362..264690e0fb3d0c0eaba3d509a0f801f0e818e4f8 100644 (file)
@@ -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 {