Welcome! Log In Create A New Profile

Advanced

Re: terminate a connection after sending headers

September 03, 2014 10:10AM
Maxim, thank you very much for your response.

To clarify - the problem is not about freeing the request (I don't think there's a resource leak here), the problem is that the connection is just left hanging until the client closes it / the server is restarted.
It is true that write_event_handler gets initialized to zero when the request is allocated, but it is set to ngx_http_request_empty_handler before the first line of my code even runs. In ngx_http_core_content_phase there's:

if (r->content_handler) {
r->write_event_handler = ngx_http_request_empty_handler;
ngx_http_finalize_request(r, r->content_handler(r));
return NGX_OK;
}

where r->content_handler is the entry point to my code. So, unless I explicitly reset it back to NULL (something that I never saw in any other nginx module) write_event_handler will not be null and the connection will be left hanging.

I forked some sample hello world module and modified it to reproduce the problem, please check it out here:
https://github.com/erankor/nginx-hello-world-module/blob/master/ngx_http_hello_world_module.c

In that code, I'm sending the response headers and then trigger a timer for 1 second. In the timer callback I close the request with NGX_ERROR, but the connection remains active (I used a timer here since that's the easiest solution to defer the execution, in my real project I'm performing asynchronous file I/O)

Thank you !

Eran
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: 174
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready