From 80c5e451b6453c8bb0d6b8d18b0cd335bb5a8ab7 Mon Sep 17 00:00:00 2001 From: Weibin Yao Date: Thu, 11 Mar 2010 16:50:39 +0800 Subject: [PATCH] fix a write NULL event bug --- modules/ngx_tcp_proxy_module.c | 10 +++++----- ngx_tcp_upstream.c | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/ngx_tcp_proxy_module.c b/modules/ngx_tcp_proxy_module.c index 00fb058..10ab8d9 100644 --- a/modules/ngx_tcp_proxy_module.c +++ b/modules/ngx_tcp_proxy_module.c @@ -107,7 +107,8 @@ ngx_tcp_upstream_proxy_generic_handler(ngx_tcp_session_t *s, ngx_tcp_upstream_t ngx_tcp_proxy_conf_t *pcf; ngx_tcp_proxy_ctx_t *pctx; - ngx_connection_t *c; + ngx_connection_t *c; + c = s->connection; c->log->action = "ngx_tcp_proxy_handler"; @@ -184,7 +185,7 @@ ngx_tcp_proxy_init_session(ngx_connection_t *c, ngx_tcp_session_t *s) { return; } - c->read->handler = ngx_tcp_proxy_dummy_write_handler; + c->write->handler = ngx_tcp_proxy_dummy_write_handler; c->read->handler = ngx_tcp_proxy_dummy_read_handler; if (ngx_tcp_upstream_create(s) != NGX_OK) { @@ -242,7 +243,7 @@ ngx_tcp_proxy_init(ngx_connection_t *c, ngx_tcp_session_t *s) { return; } -static ngx_int_t +ngx_int_t ngx_tcp_proxy_test_connect(ngx_connection_t *c) { int err; @@ -296,8 +297,7 @@ ngx_tcp_proxy_dummy_write_handler(ngx_event_t *wev) { ngx_log_debug1(NGX_LOG_DEBUG_TCP, wev->log, 0, "tcp proxy dummy write handler: %d", c->fd); - if (ngx_tcp_proxy_test_connect(c) != NGX_OK - || ngx_handle_write_event(wev, 0) != NGX_OK) { + if (ngx_handle_write_event(wev, 0) != NGX_OK) { ngx_tcp_finalize_session(s); } } diff --git a/ngx_tcp_upstream.c b/ngx_tcp_upstream.c index ca9464f..96fb04e 100644 --- a/ngx_tcp_upstream.c +++ b/ngx_tcp_upstream.c @@ -417,8 +417,10 @@ ngx_tcp_upstream_connect(ngx_tcp_session_t *s, ngx_tcp_upstream_t *u) { ngx_log_debug1(NGX_LOG_DEBUG_TCP, s->connection->log, 0, "tcp upstream connect: %d", rc); if (rc != NGX_OK && rc != NGX_AGAIN) { + ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, - "upstream servers error or busy!", rc); + "upstream servers error or busy!"); + ngx_tcp_upstream_finalize_session(s, u, 0); return; }