mirror of
https://github.com/haproxy/haproxy.git
synced 2026-04-21 22:28:41 -04:00
Revert "MINOR: queue: factor out the proxy/server queuing code"
This reverts commit3eecdb65c5. The recent changes since5304669e1MEDIUM: queue: make pendconn_process_next_strm() only return the pendconn opened a tiny race condition between stream_free() and process_srv_queue(), as the pendconn is accessed outside of the lock, possibly while it's being freed. A different approach is required.
This commit is contained in:
parent
a4a9bbadc6
commit
58f4dfb2b0
1 changed files with 27 additions and 19 deletions
46
src/queue.c
46
src/queue.c
|
|
@ -391,9 +391,6 @@ struct pendconn *pendconn_add(struct stream *strm)
|
|||
struct pendconn *p;
|
||||
struct proxy *px;
|
||||
struct server *srv;
|
||||
struct queue *q;
|
||||
unsigned int *max_ptr;
|
||||
unsigned int old_max, new_max;
|
||||
|
||||
p = pool_alloc(pool_head_pendconn);
|
||||
if (!p)
|
||||
|
|
@ -414,26 +411,37 @@ struct pendconn *pendconn_add(struct stream *strm)
|
|||
strm->pend_pos = p;
|
||||
|
||||
if (srv) {
|
||||
q = &srv->queue;
|
||||
max_ptr = &srv->counters.nbpend_max;
|
||||
unsigned int old_max, new_max;
|
||||
|
||||
new_max = _HA_ATOMIC_ADD_FETCH(&srv->queue.length, 1);
|
||||
old_max = srv->counters.nbpend_max;
|
||||
while (new_max > old_max) {
|
||||
if (likely(_HA_ATOMIC_CAS(&srv->counters.nbpend_max, &old_max, new_max)))
|
||||
break;
|
||||
}
|
||||
__ha_barrier_atomic_store();
|
||||
|
||||
HA_SPIN_LOCK(QUEUE_LOCK, &p->srv->queue.lock);
|
||||
p->queue_idx = srv->queue.idx - 1; // for increment
|
||||
eb32_insert(&srv->queue.head, &p->node);
|
||||
HA_SPIN_UNLOCK(QUEUE_LOCK, &p->srv->queue.lock);
|
||||
}
|
||||
else {
|
||||
q = &px->queue;
|
||||
max_ptr = &px->be_counters.nbpend_max;
|
||||
}
|
||||
unsigned int old_max, new_max;
|
||||
|
||||
new_max = _HA_ATOMIC_ADD_FETCH(&q->length, 1);
|
||||
old_max = _HA_ATOMIC_LOAD(max_ptr);
|
||||
while (new_max > old_max) {
|
||||
if (likely(_HA_ATOMIC_CAS(max_ptr, &old_max, new_max)))
|
||||
break;
|
||||
}
|
||||
__ha_barrier_atomic_store();
|
||||
new_max = _HA_ATOMIC_ADD_FETCH(&px->queue.length, 1);
|
||||
old_max = px->be_counters.nbpend_max;
|
||||
while (new_max > old_max) {
|
||||
if (likely(_HA_ATOMIC_CAS(&px->be_counters.nbpend_max, &old_max, new_max)))
|
||||
break;
|
||||
}
|
||||
__ha_barrier_atomic_store();
|
||||
|
||||
HA_SPIN_LOCK(QUEUE_LOCK, &q->lock);
|
||||
p->queue_idx = q->idx - 1; // for increment
|
||||
eb32_insert(&q->head, &p->node);
|
||||
HA_SPIN_UNLOCK(QUEUE_LOCK, &q->lock);
|
||||
HA_SPIN_LOCK(QUEUE_LOCK, &p->px->queue.lock);
|
||||
p->queue_idx = px->queue.idx - 1; // for increment
|
||||
eb32_insert(&px->queue.head, &p->node);
|
||||
HA_SPIN_UNLOCK(QUEUE_LOCK, &p->px->queue.lock);
|
||||
}
|
||||
|
||||
_HA_ATOMIC_INC(&px->totpend);
|
||||
return p;
|
||||
|
|
|
|||
Loading…
Reference in a new issue