blob: bda7e4b20268e5caeb5bfc8062a686722156f163 [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001From b0b25fbc041a148d1de09f5a6503cd95973ec77c Mon Sep 17 00:00:00 2001
2From: Richard Purdie <richard.purdie@linuxfoundation.org>
3Date: Tue, 25 Apr 2017 15:25:54 +0100
4Subject: [PATCH 3/3] pseudo: Handle too many files deadlock
5
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006Currently if we max out the maximum number of files, pseudo can deadlock, unable to
7accept new connections yet unable to move forward and unblock the other processes
8waiting either.
9
10Rather than hang, when this happens, close out inactive connections, allowing us
11to accept the new ones. The disconnected clients will simply reconnect. There is
12a small risk of data loss here sadly but its better than hanging.
13
14RP
152017/4/25
16
17Upstream-Status: Submitted [Peter is aware of the issue]
18
Brad Bishop316dfdd2018-06-25 12:45:53 -040019---
20 pseudo_server.c | 10 ++++++++++
21 1 file changed, 10 insertions(+)
22
23diff --git a/pseudo_server.c b/pseudo_server.c
24index dac3258..15a3e8f 100644
25--- a/pseudo_server.c
26+++ b/pseudo_server.c
27@@ -802,6 +802,7 @@ pseudo_server_loop(void) {
28 struct sigaction eat_usr2 = {
29 .sa_handler = set_do_list_clients
30 };
Brad Bishopd7bf8c12018-02-25 22:55:05 -050031+ int hitmaxfiles;
32
33 clients = malloc(16 * sizeof(*clients));
34
Brad Bishop316dfdd2018-06-25 12:45:53 -040035@@ -820,6 +821,7 @@ pseudo_server_loop(void) {
Brad Bishopd7bf8c12018-02-25 22:55:05 -050036 active_clients = 1;
37 max_clients = 16;
38 highest_client = 0;
39+ hitmaxfiles = 0;
40
41 pseudo_debug(PDBGF_SERVER, "server loop started.\n");
42 if (listen_fd < 0) {
Brad Bishop316dfdd2018-06-25 12:45:53 -040043@@ -878,10 +880,15 @@ pseudo_server_loop(void) {
44 } else {
45 serve_client(i);
Brad Bishopd7bf8c12018-02-25 22:55:05 -050046 }
47+ } else if (hitmaxfiles) {
48+ /* Only close one per loop iteration in the interests of caution */
49+ close_client(i);
50+ hitmaxfiles = 0;
51 }
52 if (die_forcefully)
53 break;
54 }
55+ hitmaxfiles = 0;
56 if (!die_forcefully &&
57 (FD_ISSET(clients[0].fd, &events) ||
58 FD_ISSET(clients[0].fd, &reads))) {
Brad Bishop316dfdd2018-06-25 12:45:53 -040059@@ -903,6 +910,9 @@ pseudo_server_loop(void) {
60 */
61 pseudo_server_timeout = DEFAULT_PSEUDO_SERVER_TIMEOUT;
62 die_peacefully = 0;
Brad Bishopd7bf8c12018-02-25 22:55:05 -050063+ } else if (errno == EMFILE) {
64+ hitmaxfiles = 1;
65+ pseudo_debug(PDBGF_SERVER, "Hit max open files, dropping a client.\n");
66 }
67 }
68 pseudo_debug(PDBGF_SERVER, "server loop complete [%d clients left]\n", active_clients);
Brad Bishop316dfdd2018-06-25 12:45:53 -040069--
702.15.1
71