Mercurial > hg > nginx
comparison src/http/modules/ngx_http_limit_zone_module.c @ 4515:8bb695c05870 stable-1.0
Merge of r4498:
Fix of rbtree lookup on hash collisions.
Previous code incorrectly assumed that nodes with identical keys are linked
together. This might not be true after tree rebalance.
Patch by Lanshun Zhou.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 05 Mar 2012 13:17:56 +0000 |
parents | 4919fb357a5d |
children | 50143b8fb95f |
comparison
equal
deleted
inserted
replaced
4514:79142134d616 | 4515:8bb695c05870 |
---|---|
192 continue; | 192 continue; |
193 } | 193 } |
194 | 194 |
195 /* hash == node->key */ | 195 /* hash == node->key */ |
196 | 196 |
197 do { | 197 lz = (ngx_http_limit_zone_node_t *) &node->color; |
198 lz = (ngx_http_limit_zone_node_t *) &node->color; | 198 |
199 | 199 rc = ngx_memn2cmp(vv->data, lz->data, len, (size_t) lz->len); |
200 rc = ngx_memn2cmp(vv->data, lz->data, len, (size_t) lz->len); | 200 |
201 | 201 if (rc == 0) { |
202 if (rc == 0) { | 202 if ((ngx_uint_t) lz->conn < lzcf->conn) { |
203 if ((ngx_uint_t) lz->conn < lzcf->conn) { | 203 lz->conn++; |
204 lz->conn++; | 204 goto done; |
205 goto done; | |
206 } | |
207 | |
208 ngx_shmtx_unlock(&shpool->mutex); | |
209 | |
210 ngx_log_error(lzcf->log_level, r->connection->log, 0, | |
211 "limiting connections by zone \"%V\"", | |
212 &lzcf->shm_zone->shm.name); | |
213 | |
214 return NGX_HTTP_SERVICE_UNAVAILABLE; | |
215 } | 205 } |
216 | 206 |
217 node = (rc < 0) ? node->left : node->right; | 207 ngx_shmtx_unlock(&shpool->mutex); |
218 | 208 |
219 } while (node != sentinel && hash == node->key); | 209 ngx_log_error(lzcf->log_level, r->connection->log, 0, |
220 | 210 "limiting connections by zone \"%V\"", |
221 break; | 211 &lzcf->shm_zone->shm.name); |
212 | |
213 return NGX_HTTP_SERVICE_UNAVAILABLE; | |
214 } | |
215 | |
216 node = (rc < 0) ? node->left : node->right; | |
222 } | 217 } |
223 | 218 |
224 n = offsetof(ngx_rbtree_node_t, color) | 219 n = offsetof(ngx_rbtree_node_t, color) |
225 + offsetof(ngx_http_limit_zone_node_t, data) | 220 + offsetof(ngx_http_limit_zone_node_t, data) |
226 + len; | 221 + len; |