Mercurial > hg > ngx_http_upstream_keepalive
diff ngx_http_upstream_keepalive_module.c @ 21:9a4ee6fe1c6d
Keepalive: avoid closing upstream connection on stale events.
Under some conditions it's possible that stale events occur, i.e. read
event handler called for just saved upstream connection without any data
available for read. We shouldn't close upstream connection in such
situation.
Reported by: Martin Fjordvald
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 14 Sep 2010 04:01:14 +0400 |
parents | 2054159546d0 |
children | 2ee28064a04a |
line wrap: on
line diff
--- a/ngx_http_upstream_keepalive_module.c +++ b/ngx_http_upstream_keepalive_module.c @@ -386,12 +386,29 @@ ngx_http_upstream_keepalive_close_handle ngx_http_upstream_keepalive_srv_conf_t *conf; ngx_http_upstream_keepalive_cache_t *item; + int n; + char buf[1]; ngx_connection_t *c; ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0, "keepalive close handler"); c = ev->data; + + n = recv(c->fd, buf, 1, MSG_PEEK); + + if (n == -1 && ngx_socket_errno == NGX_EAGAIN) { + /* stale event */ + + if (ngx_handle_read_event(c->read, 0) != NGX_OK) { + goto close; + } + + return; + } + +close: + item = c->data; conf = item->conf;