diff options
Diffstat (limited to '')
| -rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.c | 31 | ||||
| -rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_upstream.c | 3 | ||||
| -rw-r--r-- | src/http/ngx_http_request.c | 20 |
3 files changed, 41 insertions, 13 deletions
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c index 5d646bb1c..5479717b9 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -608,6 +608,7 @@ void ngx_http_proxy_finalize_request(ngx_http_proxy_ctx_t *p, int rc) void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p) { + ngx_socket_t fd; ngx_connection_t *c; c = p->upstream->peer.connection; @@ -650,12 +651,36 @@ void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p) } } - if (ngx_close_socket(c->fd) == -1) { - ngx_log_error(NGX_LOG_ALERT, c->log, ngx_socket_errno, - ngx_close_socket_n " failed"); + /* + * we have to clean the connection information before the closing + * because another thread may reopen the same file descriptor + * before we clean the connection + */ + + if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_OK) { + + if (c->read->prev) { + ngx_delete_posted_event(c->read); + } + + if (c->write->prev) { + ngx_delete_posted_event(c->write); + } + + c->read->closed = 1; + c->write->closed = 1; + + ngx_mutex_unlock(ngx_posted_events_mutex); } + fd = c->fd; c->fd = (ngx_socket_t) -1; + c->data = NULL; + + if (ngx_close_socket(fd) == -1) { + ngx_log_error(NGX_LOG_ALERT, c->log, ngx_socket_errno, + ngx_close_socket_n " failed"); + } } diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c index 9ed4d7f61..335d1dacd 100644 --- a/src/http/modules/proxy/ngx_http_proxy_upstream.c +++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c @@ -62,6 +62,9 @@ int ngx_http_proxy_request_upstream(ngx_http_proxy_ctx_t *p) u->peer.log_error = NGX_ERROR_ERR; u->peer.peers = p->lcf->peers; u->peer.tries = p->lcf->peers->number; +#if (NGX_THREADS) + u->peer.lock = &r->connection->lock; +#endif u->method = r->method; diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index 74618313b..e2c28913d 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -1749,13 +1749,6 @@ void ngx_http_close_connection(ngx_connection_t *c) if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_OK) { - ngx_unlock(&c->lock); - c->read->locked = 0; - c->write->locked = 0; - - c->read->closed = 1; - c->write->closed = 1; - if (c->read->prev) { ngx_delete_posted_event(c->read); } @@ -1764,14 +1757,18 @@ void ngx_http_close_connection(ngx_connection_t *c) ngx_delete_posted_event(c->write); } + c->read->closed = 1; + c->write->closed = 1; + + ngx_unlock(&c->lock); + c->read->locked = 0; + c->write->locked = 0; + ngx_mutex_unlock(ngx_posted_events_mutex); } #else - c->read->closed = 1; - c->write->closed = 1; - if (c->read->prev) { ngx_delete_posted_event(c->read); } @@ -1780,6 +1777,9 @@ void ngx_http_close_connection(ngx_connection_t *c) ngx_delete_posted_event(c->write); } + c->read->closed = 1; + c->write->closed = 1; + #endif fd = c->fd; |
