531cde94a9c96b6d01cdccaabfa5ca6d1d3161de
[openwrt-packages.git] /
1 commit 000f227a4cfdb019575e889638f9e0e5a53bbb0b
2 Author: Olivier Houchard <cognet@ci0.org>
3 Date:   Mon Dec 30 18:15:40 2019 +0100
4
5     BUG/MEDIUM: connections: Hold the lock when wanting to kill a connection.
6     
7     In connect_server(), when we decide we want to kill the connection of
8     another thread because there are too many idle connections, hold the
9     toremove_lock of the corresponding thread, othervise, there's a small race
10     condition where we could try to add the connection to the toremove_connections
11     list while it has already been free'd.
12     
13     This should be backported to 2.0 and 2.1.
14     
15     (cherry picked from commit 140237471e408736bb7162e68c572c710a66a526)
16     Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
17
18 diff --git a/src/backend.c b/src/backend.c
19 index ebc5050cb..be081a5e1 100644
20 --- a/src/backend.c
21 +++ b/src/backend.c
22 @@ -1295,6 +1295,7 @@ int connect_server(struct stream *s)
23                                 // see it possibly larger.
24                                 ALREADY_CHECKED(i);
25  
26 +                               HA_SPIN_LOCK(OTHER_LOCK, &toremove_lock[tid]);
27                                 tokill_conn = MT_LIST_POP(&srv->idle_orphan_conns[i],
28                                     struct connection *, list);
29                                 if (tokill_conn) {
30 @@ -1305,6 +1306,7 @@ int connect_server(struct stream *s)
31                                         task_wakeup(idle_conn_cleanup[i], TASK_WOKEN_OTHER);
32                                         break;
33                                 }
34 +                               HA_SPIN_UNLOCK(OTHER_LOCK, &toremove_lock[tid]);
35                         }
36                 }
37  
git clone https://git.99rst.org/PROJECT