Welcome! Log In Create A New Profile

Advanced

Re: terminate a connection after sending headers

Maxim Dounin
September 02, 2014 09:10AM
Hello!

On Mon, Sep 01, 2014 at 05:25:56PM -0400, erankor2 wrote:

> 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).

The r->write_event_handler is set to NULL on initial creation of a
request. If write_event_handler is not NULL during a request
termination, nginx posts an event instead of freeing the request
request directly (this is done to avoid use-after-free when
processing posted subrequests). The request is still freed
though.

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

terminate a connection after sending headers

erankor2 September 01, 2014 05:25PM

Re: terminate a connection after sending headers

Maxim Dounin September 02, 2014 09:10AM

Re: terminate a connection after sending headers

erankor2 September 03, 2014 10:10AM

Re: terminate a connection after sending headers

Maxim Dounin September 03, 2014 09:12PM

Re: terminate a connection after sending headers

erankor2 September 04, 2014 04:38PM

Re: terminate a connection after sending headers

Maxim Dounin September 05, 2014 12:36AM

Re: terminate a connection after sending headers

erankor2 September 07, 2014 04:49PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 55
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready