terminate a connection after sending headers

erankor2 nginx-forum at nginx.us
Mon Sep 1 21:25:56 UTC 2014

Hi all,

In the module I'm developing, I have the possibility of encountering an
error after the response headers were already sent. As the headers were
already sent (with status 200) the only way for me to signal the error to
the client would be to close the connection. I tried calling
ngx_http_finalize_request with both NGX_ERROR and NGX_HTTP_CLOSE and the
connection is not closed. 
After debugging it, I found it has to do with the 'if
(mr->write_event_handler)' in ngx_http_terminate_request. I'm not sure what
is the purpose of this if, but in my case write_event_handler has the value
ngx_http_request_empty_handler, so the if evaluates to true and the
connection is not terminated. When I forcefully change write_event_handler
to NULL with GDB, I see the connection is closed as expected. 
I searched the code for 'write_event_handler =' and could not find a single
place where this member gets a value of NULL (it always gets a pointer to
some function).

Can anyone confirm if this is really a bug ? maybe the if should be updated
to 'if (mr->write_event_handler != ngx_http_request_empty_handler)' ?

Thank you,


Posted at Nginx Forum: http://forum.nginx.org/read.php?2,253006,253006#msg-253006

More information about the nginx mailing list