s3: winbindd: On new client connect, prune idle or hung connections older than "winbi...
authorJeremy Allison <jra@samba.org>
Fri, 25 Jul 2014 19:46:46 +0000 (12:46 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 29 Jul 2014 21:31:14 +0000 (23:31 +0200)
Bug 3204 winbindd: Exceeding 200 client connections, no idle connection found

https://bugzilla.samba.org/show_bug.cgi?id=3204

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ira Cooper <ira@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Tue Jul 29 23:31:14 CEST 2014 on sn-devel-104

source3/winbindd/winbindd.c

index a51a172973b7e0ffd8c1ae5f184d490f2af22a88..caa9ed127dd7aa1e8d23fad28f983bec68638a58 100644 (file)
@@ -1031,6 +1031,41 @@ static bool remove_idle_client(void)
        return False;
 }
 
+/*
+ * Terminate all clients whose requests have taken longer than
+ * "winbind request timeout" seconds to process, or have been
+ * idle for more than "winbind request timeout" seconds.
+ */
+
+static void remove_timed_out_clients(void)
+{
+       struct winbindd_cli_state *state, *next = NULL;
+       time_t curr_time = time(NULL);
+       int timeout_val = lp_winbind_request_timeout();
+
+       for (state = winbindd_client_list(); state; state = next) {
+               time_t expiry_time;
+
+               next = state->next;
+               expiry_time = state->last_access + timeout_val;
+
+               if (curr_time > expiry_time) {
+                       if (client_is_idle(state)) {
+                               DEBUG(5,("Idle client timed out, "
+                                       "shutting down sock %d, pid %u\n",
+                                       state->sock,
+                                       (unsigned int)state->pid));
+                       } else {
+                               DEBUG(5,("Client request timed out, "
+                                       "shutting down sock %d, pid %u\n",
+                                       state->sock,
+                                       (unsigned int)state->pid));
+                       }
+                       remove_client(state);
+               }
+       }
+}
+
 struct winbindd_listen_state {
        bool privileged;
        int fd;
@@ -1056,6 +1091,7 @@ static void winbindd_listen_fde_handler(struct tevent_context *ev,
                        break;
                }
        }
+       remove_timed_out_clients();
        new_connection(s->fd, s->privileged);
 }