blob: 1c730c75c893edc004094f1aee49afa762b15e4d [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 * Queue management functions.
3 *
Willy Tarreauac68c5d2009-10-04 23:12:44 +02004 * Copyright 2000-2009 Willy Tarreau <w@1wt.eu>
Willy Tarreaubaaee002006-06-26 02:48:02 +02005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020013#include <common/config.h>
Willy Tarreaue4d7e552007-05-13 20:19:55 +020014#include <common/memory.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020015#include <common/time.h>
Christopher Faulet8ba59142017-06-27 15:43:53 +020016#include <common/hathreads.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020017
Willy Tarreaubaaee002006-06-26 02:48:02 +020018#include <proto/queue.h>
19#include <proto/server.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020020#include <proto/stream.h>
Willy Tarreau9e000c62011-03-10 14:03:36 +010021#include <proto/stream_interface.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020022#include <proto/task.h>
23
24
Willy Tarreaubafbe012017-11-24 17:34:44 +010025struct pool_head *pool_head_pendconn;
Willy Tarreaue4d7e552007-05-13 20:19:55 +020026
27/* perform minimal intializations, report 0 in case of error, 1 if OK. */
28int init_pendconn()
29{
Willy Tarreaubafbe012017-11-24 17:34:44 +010030 pool_head_pendconn = create_pool("pendconn", sizeof(struct pendconn), MEM_F_SHARED);
31 return pool_head_pendconn != NULL;
Willy Tarreaue4d7e552007-05-13 20:19:55 +020032}
Willy Tarreaubaaee002006-06-26 02:48:02 +020033
34/* returns the effective dynamic maxconn for a server, considering the minconn
Willy Tarreau86034312006-12-29 00:10:33 +010035 * and the proxy's usage relative to its dynamic connections limit. It is
Willy Tarreau9909fc12007-11-30 17:42:05 +010036 * expected that 0 < s->minconn <= s->maxconn when this is called. If the
37 * server is currently warming up, the slowstart is also applied to the
38 * resulting value, which can be lower than minconn in this case, but never
39 * less than 1.
Willy Tarreaubaaee002006-06-26 02:48:02 +020040 */
Willy Tarreaub17916e2006-10-15 15:17:57 +020041unsigned int srv_dynamic_maxconn(const struct server *s)
Willy Tarreaubaaee002006-06-26 02:48:02 +020042{
Willy Tarreau9909fc12007-11-30 17:42:05 +010043 unsigned int max;
44
Willy Tarreau86034312006-12-29 00:10:33 +010045 if (s->proxy->beconn >= s->proxy->fullconn)
46 /* no fullconn or proxy is full */
Willy Tarreau9909fc12007-11-30 17:42:05 +010047 max = s->maxconn;
48 else if (s->minconn == s->maxconn)
Willy Tarreau86034312006-12-29 00:10:33 +010049 /* static limit */
Willy Tarreau9909fc12007-11-30 17:42:05 +010050 max = s->maxconn;
51 else max = MAX(s->minconn,
52 s->proxy->beconn * s->maxconn / s->proxy->fullconn);
Willy Tarreau86034312006-12-29 00:10:33 +010053
Emeric Brun52a91d32017-08-31 14:41:55 +020054 if ((s->cur_state == SRV_ST_STARTING) &&
Willy Tarreau9909fc12007-11-30 17:42:05 +010055 now.tv_sec < s->last_change + s->slowstart &&
56 now.tv_sec >= s->last_change) {
57 unsigned int ratio;
Willy Tarreau28a9e522008-09-14 17:43:27 +020058 ratio = 100 * (now.tv_sec - s->last_change) / s->slowstart;
59 max = MAX(1, max * ratio / 100);
Willy Tarreau9909fc12007-11-30 17:42:05 +010060 }
61 return max;
Willy Tarreaubaaee002006-06-26 02:48:02 +020062}
63
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +010064/* Remove the pendconn from the server/proxy queue. At this stage, the
65 * connection is not really dequeued. It will be done during the
66 * process_stream. This function must be called by function owning the locks on
67 * the pendconn _AND_ the server/proxy. It also decreases the pending count.
68 *
69 * The caller must own the lock on the pendconn _AND_ the queue containing the
70 * pendconn. The pendconn must still be queued.
Christopher Fauletf3a55db2017-06-09 14:26:38 +020071 */
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +010072static void pendconn_unlink(struct pendconn *p)
73{
74 if (p->srv)
75 p->srv->nbpend--;
76 else
77 p->px->nbpend--;
78 HA_ATOMIC_SUB(&p->px->totpend, 1);
79 LIST_DEL(&p->list);
80 LIST_INIT(&p->list);
Christopher Fauletf3a55db2017-06-09 14:26:38 +020081}
82
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +010083/* Process the next pending connection from either a server or a proxy, and
Christopher Fauletfd83f0b2018-03-19 15:22:09 +010084 * returns a strictly positive value on success (see below). If no pending
85 * connection is found, 0 is returned. Note that neither <srv> nor <px> may be
86 * NULL. Priority is given to the oldest request in the queue if both <srv> and
87 * <px> have pending requests. This ensures that no request will be left
88 * unserved. The <px> queue is not considered if the server (or a tracked
89 * server) is not RUNNING, is disabled, or has a null weight (server going
90 * down). The <srv> queue is still considered in this case, because if some
91 * connections remain there, it means that some requests have been forced there
92 * after it was seen down (eg: due to option persist). The stream is
93 * immediately marked as "assigned", and both its <srv> and <srv_conn> are set
94 * to <srv>.
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +010095 *
96 * This function must only be called if the server queue _AND_ the proxy queue
Christopher Fauletfd83f0b2018-03-19 15:22:09 +010097 * are locked. Today it is only called by process_srv_queue. When a pending
98 * connection is dequeued, this function returns 1 if the pending connection can
99 * be handled by the current thread, else it returns 2.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200100 */
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100101static int pendconn_process_next_strm(struct server *srv, struct proxy *px)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200102{
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100103 struct pendconn *p = NULL;
104 struct server *rsrv;
Christopher Fauletfd83f0b2018-03-19 15:22:09 +0100105 int remote;
Willy Tarreaud132f742010-08-06 10:08:23 +0200106
Willy Tarreau44267702011-10-28 15:35:33 +0200107 rsrv = srv->track;
Willy Tarreaud132f742010-08-06 10:08:23 +0200108 if (!rsrv)
109 rsrv = srv;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200110
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100111 if (srv->nbpend) {
112 list_for_each_entry(p, &srv->pendconns, list) {
113 if (!HA_SPIN_TRYLOCK(PENDCONN_LOCK, &p->lock))
114 goto ps_found;
115 }
116 p = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200117 }
Willy Tarreau7c669d72008-06-20 15:04:11 +0200118
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100119 ps_found:
120 if (srv_currently_usable(rsrv) && px->nbpend) {
121 struct pendconn *pp;
122
123 list_for_each_entry(pp, &px->pendconns, list) {
124 /* If the server pendconn is older than the proxy one,
125 * we process the server one. */
126 if (p && !tv_islt(&pp->strm->logs.tv_request, &p->strm->logs.tv_request))
127 goto pendconn_found;
128
129 if (!HA_SPIN_TRYLOCK(PENDCONN_LOCK, &pp->lock)) {
130 /* Let's switch from the server pendconn to the
131 * proxy pendconn. Don't forget to unlock the
132 * server pendconn, if any. */
133 if (p)
134 HA_SPIN_UNLOCK(PENDCONN_LOCK, &p->lock);
135 p = pp;
136 goto pendconn_found;
137 }
138 }
139 }
140
141 if (!p)
Christopher Fauletfd83f0b2018-03-19 15:22:09 +0100142 return 0;
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100143
144 pendconn_found:
145 pendconn_unlink(p);
146 p->strm_flags |= SF_ASSIGNED;
147 p->srv = srv;
148
Christopher Faulet29f77e82017-06-08 14:04:45 +0200149 HA_ATOMIC_ADD(&srv->served, 1);
Christopher Fauletff8abcd2017-06-02 15:33:24 +0200150 HA_ATOMIC_ADD(&srv->proxy->served, 1);
Willy Tarreau7c669d72008-06-20 15:04:11 +0200151 if (px->lbprm.server_take_conn)
152 px->lbprm.server_take_conn(srv);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100153 __stream_add_srv_conn(p->strm, srv);
Willy Tarreau7c669d72008-06-20 15:04:11 +0200154
Christopher Fauletfd83f0b2018-03-19 15:22:09 +0100155 remote = !(p->strm->task->thread_mask & tid_bit);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100156 task_wakeup(p->strm->task, TASK_WOKEN_RES);
157 HA_SPIN_UNLOCK(PENDCONN_LOCK, &p->lock);
Christopher Fauletfd83f0b2018-03-19 15:22:09 +0100158
159 /* Returns 1 if the current thread can process the stream, otherwise returns 2. */
160 return remote ? 2 : 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200161}
162
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100163/* Manages a server's connection queue. This function will try to dequeue as
Christopher Faulet87566c92017-06-06 10:34:51 +0200164 * many pending streams as possible, and wake them up.
165 */
166void process_srv_queue(struct server *s)
167{
168 struct proxy *p = s->proxy;
Christopher Fauletfd83f0b2018-03-19 15:22:09 +0100169 int maxconn, remote = 0;
Christopher Faulet87566c92017-06-06 10:34:51 +0200170
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100171 HA_SPIN_LOCK(PROXY_LOCK, &p->lock);
172 HA_SPIN_LOCK(SERVER_LOCK, &s->lock);
Christopher Faulet87566c92017-06-06 10:34:51 +0200173 maxconn = srv_dynamic_maxconn(s);
174 while (s->served < maxconn) {
Christopher Fauletfd83f0b2018-03-19 15:22:09 +0100175 int ret = pendconn_process_next_strm(s, p);
176 if (!ret)
Christopher Faulet87566c92017-06-06 10:34:51 +0200177 break;
Christopher Fauletfd83f0b2018-03-19 15:22:09 +0100178 remote |= (ret == 2);
Christopher Faulet87566c92017-06-06 10:34:51 +0200179 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100180 HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock);
181 HA_SPIN_UNLOCK(PROXY_LOCK, &p->lock);
Christopher Fauletfd83f0b2018-03-19 15:22:09 +0100182
183 if (remote)
Ilya Shipitsin7741c852018-03-24 17:17:32 +0500184 THREAD_WANT_SYNC();
Christopher Faulet87566c92017-06-06 10:34:51 +0200185}
186
Willy Tarreau87b09662015-04-03 00:22:06 +0200187/* Adds the stream <strm> to the pending connection list of server <strm>->srv
188 * or to the one of <strm>->proxy if srv is NULL. All counters and back pointers
Willy Tarreaubaaee002006-06-26 02:48:02 +0200189 * are updated accordingly. Returns NULL if no memory is available, otherwise the
Willy Tarreau87b09662015-04-03 00:22:06 +0200190 * pendconn itself. If the stream was already marked as served, its flag is
191 * cleared. It is illegal to call this function with a non-NULL strm->srv_conn.
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100192 *
193 * This function must be called by the stream itself, so in the context of
194 * process_stream.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200195 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200196struct pendconn *pendconn_add(struct stream *strm)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200197{
198 struct pendconn *p;
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100199 struct proxy *px;
200 struct server *srv;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200201
Willy Tarreaubafbe012017-11-24 17:34:44 +0100202 p = pool_alloc(pool_head_pendconn);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200203 if (!p)
204 return NULL;
205
Christopher Faulet8ba59142017-06-27 15:43:53 +0200206 srv = objt_server(strm->target);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100207 px = strm->be;
208
209 p->srv = NULL;
210 p->px = px;
211 p->strm = strm;
212 p->strm_flags = strm->flags;
213 HA_SPIN_INIT(&p->lock);
Willy Tarreau7c669d72008-06-20 15:04:11 +0200214
Christopher Faulet8ba59142017-06-27 15:43:53 +0200215 if ((strm->flags & SF_ASSIGNED) && srv) {
216 p->srv = srv;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100217 HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100218 srv->nbpend++;
219 strm->logs.srv_queue_size += srv->nbpend;
220 if (srv->nbpend > srv->counters.nbpend_max)
221 srv->counters.nbpend_max = srv->nbpend;
Willy Tarreau827aee92011-03-10 16:55:02 +0100222 LIST_ADDQ(&srv->pendconns, &p->list);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100223 HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100224 }
225 else {
226 HA_SPIN_LOCK(PROXY_LOCK, &px->lock);
227 px->nbpend++;
228 strm->logs.prx_queue_size += px->nbpend;
229 if (px->nbpend > px->be_counters.nbpend_max)
230 px->be_counters.nbpend_max = px->nbpend;
231 LIST_ADDQ(&px->pendconns, &p->list);
232 HA_SPIN_UNLOCK(PROXY_LOCK, &px->lock);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200233 }
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100234 HA_ATOMIC_ADD(&px->totpend, 1);
235 strm->pend_pos = p;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200236 return p;
237}
238
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200239/* Redistribute pending connections when a server goes down. The number of
240 * connections redistributed is returned.
241 */
242int pendconn_redistribute(struct server *s)
243{
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100244 struct pendconn *p, *pback;
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200245 int xferred = 0;
Christopher Fauletfd83f0b2018-03-19 15:22:09 +0100246 int remote = 0;
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200247
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100248 /* The REDISP option was specified. We will ignore cookie and force to
249 * balance or use the dispatcher. */
250 if ((s->proxy->options & (PR_O_REDISP|PR_O_PERSIST)) != PR_O_REDISP)
251 return 0;
252
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100253 HA_SPIN_LOCK(SERVER_LOCK, &s->lock);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100254 list_for_each_entry_safe(p, pback, &s->pendconns, list) {
255 if (p->strm_flags & SF_FORCE_PRST)
256 continue;
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200257
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100258 if (HA_SPIN_TRYLOCK(PENDCONN_LOCK, &p->lock))
259 continue;
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200260
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100261 /* it's left to the dispatcher to choose a server */
262 pendconn_unlink(p);
263 p->strm_flags &= ~(SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET);
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200264
Christopher Fauletfd83f0b2018-03-19 15:22:09 +0100265 remote |= !(p->strm->task->thread_mask & tid_bit);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100266 task_wakeup(p->strm->task, TASK_WOKEN_RES);
267 HA_SPIN_UNLOCK(PENDCONN_LOCK, &p->lock);
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200268 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100269 HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock);
Christopher Fauletfd83f0b2018-03-19 15:22:09 +0100270
271 if (remote)
Ilya Shipitsin7741c852018-03-24 17:17:32 +0500272 THREAD_WANT_SYNC();
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200273 return xferred;
274}
275
276/* Check for pending connections at the backend, and assign some of them to
277 * the server coming up. The server's weight is checked before being assigned
278 * connections it may not be able to handle. The total number of transferred
279 * connections is returned.
280 */
281int pendconn_grab_from_px(struct server *s)
282{
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100283 struct pendconn *p, *pback;
284 int maxconn, xferred = 0;
Christopher Fauletfd83f0b2018-03-19 15:22:09 +0100285 int remote = 0;
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200286
Emeric Brun52a91d32017-08-31 14:41:55 +0200287 if (!srv_currently_usable(s))
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200288 return 0;
289
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100290 HA_SPIN_LOCK(PROXY_LOCK, &s->proxy->lock);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100291 maxconn = srv_dynamic_maxconn(s);
292 list_for_each_entry_safe(p, pback, &s->proxy->pendconns, list) {
293 if (s->maxconn && s->served + xferred >= maxconn)
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200294 break;
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100295
296 if (HA_SPIN_TRYLOCK(PENDCONN_LOCK, &p->lock))
297 continue;
298
299 pendconn_unlink(p);
300 p->srv = s;
301
Christopher Fauletfd83f0b2018-03-19 15:22:09 +0100302 remote |= !(p->strm->task->thread_mask & tid_bit);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100303 task_wakeup(p->strm->task, TASK_WOKEN_RES);
304 HA_SPIN_UNLOCK(PENDCONN_LOCK, &p->lock);
305 xferred++;
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200306 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100307 HA_SPIN_UNLOCK(PROXY_LOCK, &s->proxy->lock);
Christopher Fauletfd83f0b2018-03-19 15:22:09 +0100308
309 if (remote)
Ilya Shipitsin7741c852018-03-24 17:17:32 +0500310 THREAD_WANT_SYNC();
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200311 return xferred;
312}
313
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100314/* Try to dequeue pending connection attached to the stream <strm>. It must
315 * always exists here. If the pendconn is still linked to the server or the
316 * proxy queue, nothing is done and the function returns 1. Otherwise,
317 * <strm>->flags and <strm>->target are updated, the pendconn is released and 0
318 * is returned.
319 *
320 * This function must be called by the stream itself, so in the context of
321 * process_stream.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200322 */
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100323int pendconn_dequeue(struct stream *strm)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200324{
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100325 struct pendconn *p;
326
327 if (unlikely(!strm->pend_pos)) {
328 /* unexpected case because it is called by the stream itself and
329 * only the stream can release a pendconn. So it is only
330 * possible if a pendconn is released by someone else or if the
331 * stream is supposed to be queued but without its associated
332 * pendconn. In both cases it is a bug! */
333 abort();
Christopher Faulet8ba59142017-06-27 15:43:53 +0200334 }
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100335 p = strm->pend_pos;
336 HA_SPIN_LOCK(PENDCONN_LOCK, &p->lock);
337
338 /* the pendconn is still linked to the server/proxy queue, so unlock it
339 * and go away. */
340 if (!LIST_ISEMPTY(&p->list)) {
341 HA_SPIN_UNLOCK(PENDCONN_LOCK, &p->lock);
342 return 1;
Christopher Faulet8ba59142017-06-27 15:43:53 +0200343 }
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100344
345 /* the pendconn must be dequeued now */
346 if (p->srv)
347 strm->target = &p->srv->obj_type;
348
349 strm->flags &= ~(SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET);
350 strm->flags |= p->strm_flags & (SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET);
351 strm->pend_pos = NULL;
352 HA_SPIN_UNLOCK(PENDCONN_LOCK, &p->lock);
Willy Tarreaubafbe012017-11-24 17:34:44 +0100353 pool_free(pool_head_pendconn, p);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100354 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200355}
356
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100357/* Release the pending connection <p>, and decreases the pending count if
358 * needed. The connection might have been queued to a specific server as well as
359 * to the proxy. The stream also gets marked unqueued. <p> must always be
360 * defined here. So it is the caller responsibility to check its existance.
361 *
362 * This function must be called by the stream itself, so in the context of
363 * process_stream.
364 */
365void pendconn_free(struct pendconn *p)
Christopher Faulet8ba59142017-06-27 15:43:53 +0200366{
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100367 struct stream *strm = p->strm;
368
369 HA_SPIN_LOCK(PENDCONN_LOCK, &p->lock);
370
371 /* The pendconn was already unlinked, just release it. */
372 if (LIST_ISEMPTY(&p->list))
373 goto release;
374
Christopher Faulet8ba59142017-06-27 15:43:53 +0200375 if (p->srv) {
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100376 HA_SPIN_LOCK(SERVER_LOCK, &p->srv->lock);
377 p->srv->nbpend--;
Christopher Faulet8ba59142017-06-27 15:43:53 +0200378 LIST_DEL(&p->list);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100379 HA_SPIN_UNLOCK(SERVER_LOCK, &p->srv->lock);
Christopher Faulet8ba59142017-06-27 15:43:53 +0200380 }
381 else {
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100382 HA_SPIN_LOCK(PROXY_LOCK, &p->px->lock);
383 p->px->nbpend--;
Christopher Faulet8ba59142017-06-27 15:43:53 +0200384 LIST_DEL(&p->list);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100385 HA_SPIN_UNLOCK(PROXY_LOCK, &p->px->lock);
Christopher Faulet8ba59142017-06-27 15:43:53 +0200386 }
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100387 HA_ATOMIC_SUB(&p->px->totpend, 1);
388
389 release:
390 strm->pend_pos = NULL;
391 HA_SPIN_UNLOCK(PENDCONN_LOCK, &p->lock);
Willy Tarreaubafbe012017-11-24 17:34:44 +0100392 pool_free(pool_head_pendconn, p);
Christopher Faulet8ba59142017-06-27 15:43:53 +0200393}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200394
395/*
396 * Local variables:
397 * c-indent-level: 8
398 * c-basic-offset: 8
399 * End:
400 */