[nginx] Upstream: fixed unlocked access to peer->conns.

Ruslan Ermilov ru at nginx.com
Sun Apr 19 19:41:35 UTC 2015


details:   http://hg.nginx.org/nginx/rev/4a640716f4e2
branches:  
changeset: 6114:4a640716f4e2
user:      Ruslan Ermilov <ru at nginx.com>
date:      Sun Apr 19 22:41:09 2015 +0300
description:
Upstream: fixed unlocked access to peer->conns.

diffstat:

 src/http/ngx_http_upstream_round_robin.c |  9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diffs (27 lines):

diff -r 36d99c042652 -r 4a640716f4e2 src/http/ngx_http_upstream_round_robin.c
--- a/src/http/ngx_http_upstream_round_robin.c	Thu Mar 26 14:20:51 2015 +0300
+++ b/src/http/ngx_http_upstream_round_robin.c	Sun Apr 19 22:41:09 2015 +0300
@@ -599,17 +599,20 @@ ngx_http_upstream_free_round_robin_peer(
 
     peer = rrp->current;
 
+    ngx_http_upstream_rr_peers_rlock(rrp->peers);
+    ngx_http_upstream_rr_peer_lock(rrp->peers, peer);
+
     if (rrp->peers->single) {
 
         peer->conns--;
 
+        ngx_http_upstream_rr_peer_unlock(rrp->peers, peer);
+        ngx_http_upstream_rr_peers_unlock(rrp->peers);
+
         pc->tries = 0;
         return;
     }
 
-    ngx_http_upstream_rr_peers_rlock(rrp->peers);
-    ngx_http_upstream_rr_peer_lock(rrp->peers, peer);
-
     if (state & NGX_PEER_FAILED) {
         now = ngx_time();
 



More information about the nginx-devel mailing list