From c340a2841bb14ca2fae22892f61a9470b0584c59 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Wed, 6 May 2009 08:40:44 +0000 Subject: [PATCH] delete level event of appropriate type, this should fix select()'s EBADF, WSAENOTSOCK, and "select ready != events" alerts --- src/http/ngx_http_upstream.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index 4913fe38a..b21d01ab9 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -768,6 +768,7 @@ ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, int n; char buf[1]; ngx_err_t err; + ngx_int_t event; ngx_connection_t *c; ngx_http_upstream_t *u; @@ -779,10 +780,22 @@ ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, u = r->upstream; if (c->error) { + if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && ev->active) { + + event = ev->write ? NGX_WRITE_EVENT : NGX_READ_EVENT; + + if (ngx_del_event(ev, event, 0) != NGX_OK) { + ngx_http_upstream_finalize_request(r, u, + NGX_HTTP_INTERNAL_SERVER_ERROR); + return; + } + } + if (!u->cacheable) { ngx_http_upstream_finalize_request(r, u, NGX_HTTP_CLIENT_CLOSED_REQUEST); } + return; } @@ -836,17 +849,15 @@ ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, err, "http upstream recv(): %d", n); - /* - * we do not need to disable the write event because - * that event has NGX_USE_CLEAR_EVENT type - */ - if (ev->write && (n >= 0 || err == NGX_EAGAIN)) { return; } if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && ev->active) { - if (ngx_del_event(ev, NGX_READ_EVENT, 0) == NGX_ERROR) { + + event = ev->write ? NGX_WRITE_EVENT : NGX_READ_EVENT; + + if (ngx_del_event(ev, event, 0) != NGX_OK) { ngx_http_upstream_finalize_request(r, u, NGX_HTTP_INTERNAL_SERVER_ERROR); return;