Mercurial > hg > ngx_http_upstream_keepalive
comparison 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 |
comparison
equal
deleted
inserted
replaced
20:8d8eaaf07663 | 21:9a4ee6fe1c6d |
---|---|
384 ngx_http_upstream_keepalive_close_handler(ngx_event_t *ev) | 384 ngx_http_upstream_keepalive_close_handler(ngx_event_t *ev) |
385 { | 385 { |
386 ngx_http_upstream_keepalive_srv_conf_t *conf; | 386 ngx_http_upstream_keepalive_srv_conf_t *conf; |
387 ngx_http_upstream_keepalive_cache_t *item; | 387 ngx_http_upstream_keepalive_cache_t *item; |
388 | 388 |
389 int n; | |
390 char buf[1]; | |
389 ngx_connection_t *c; | 391 ngx_connection_t *c; |
390 | 392 |
391 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0, | 393 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0, |
392 "keepalive close handler"); | 394 "keepalive close handler"); |
393 | 395 |
394 c = ev->data; | 396 c = ev->data; |
397 | |
398 n = recv(c->fd, buf, 1, MSG_PEEK); | |
399 | |
400 if (n == -1 && ngx_socket_errno == NGX_EAGAIN) { | |
401 /* stale event */ | |
402 | |
403 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { | |
404 goto close; | |
405 } | |
406 | |
407 return; | |
408 } | |
409 | |
410 close: | |
411 | |
395 item = c->data; | 412 item = c->data; |
396 conf = item->conf; | 413 conf = item->conf; |
397 | 414 |
398 ngx_queue_remove(&item->queue); | 415 ngx_queue_remove(&item->queue); |
399 ngx_close_connection(item->connection); | 416 ngx_close_connection(item->connection); |