# HG changeset patch # User Maxim Dounin # Date 1377884656 -14400 # Node ID 1608b1135a1d80d2088fe8ba79025dee74e85d5d # Parent ec0be12c8e29108cbce54e6fadc6d5554dfac948 Upstream: setting u->header_sent before ngx_http_upstream_upgrade(). Without u->header_sent set a special response might be generated following an upgraded connection. The problem appeared in 1ccdda1f37f3 (1.5.3). Catched by "header already sent" alerts in 1.5.4 after upstream timeouts. diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -2105,6 +2105,8 @@ ngx_http_upstream_send_response(ngx_http return; } + u->header_sent = 1; + if (u->upgrade) { ngx_http_upstream_upgrade(r, u); return; @@ -2131,8 +2133,6 @@ ngx_http_upstream_send_response(ngx_http } } - u->header_sent = 1; - if (r->request_body && r->request_body->temp_file) { ngx_pool_run_cleanup_file(r->pool, r->request_body->temp_file->file.fd); r->request_body->temp_file->file.fd = NGX_INVALID_FILE;