Cancel ongoing ngx_http_request_t

So I’m continuing to work on my simple timeout module:
http://forum.nginx.org/read.php?2,259019

Now, when timer elapses, I want to cancel ongoing http request, here’s
my
timer handler:

static void simple_timeout_handler(ngx_event_t* timeout_event)
{
ngx_http_request_t* request =
(ngx_http_request_t*)timeout_event->data;

ngx_log_debug0(NGX_LOG_DEBUG_HTTP, timeout_event->log, 0,
“SIMPLE TIMEOUT TIMER END”);

ngx_http_finalize_request(request, NGX_HTTP_REQUEST_TIME_OUT); // this
does not seem to work,
// as request stays in progress
}

This does not work as request still continues to be in progress. Is it
possible to terminate it immediately, and return http timeout response?

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

Ok, so I managed this to work, needed to add ngx_http_send_header and
ngx_http_finalize_request:

static void simple_timeout_handler(ngx_event_t* timeout_event)
{
ngx_int_t result;
ngx_http_request_t* request;

ngx_log_debug0(NGX_LOG_DEBUG_HTTP, timeout_event->log, 0,
“SIMPLE TIMEOUT TIMER END”);

request = (ngx_http_request_t*)timeout_event->data;

result = ngx_http_send_header(request);
ngx_http_finalize_request(request, result);
}

Everything work fine, but during the load test, after some time, a
SEGFAULT
occurs:

Thread #1 [nginx] 3352 [core: 7] (Suspended : Signal :
SIGSEGV:Segmentation
fault)
ngx_destroy_pool() at ngx_palloc.c:51 0x405187
ngx_http_free_request() at ngx_http_request.c:3,499 0x42f04b
ngx_http_set_keepalive() at ngx_http_request.c:2,901 0x4300d1
ngx_http_finalize_connection() at ngx_http_request.c:2,538 0x4300d1
ngx_http_finalize_request() at ngx_http_request.c:2,434 0x430e41
simple_timeout_handler() at simple_timeout_module.c:135 0x44a8ef
ngx_event_expire_timers() at ngx_event_timer.c:94 0x41bf5a
ngx_process_events_and_timers() at ngx_event.c:262 0x41bb86
ngx_single_process_cycle() at ngx_process_cycle.c:308 0x423c8b
main() at nginx.c:416 0x403bc6

It seems, that pool argument passed to ngx_destroy_pool is not
initialized,
any ideas why this could happen?

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs