Maxim Dounin
May 20, 2015 02:38PM
Hello!

On Wed, May 20, 2015 at 01:03:19PM -0400, donatasm wrote:

> I'm trying to build a simple timeout module using nginx timers. At the
> beginning of a request I'm firing up a timer and after time interval elapses
> I want to check if request has already completed, and if not, finalize it,
> for example it with NGX_HTTP_REQUEST_TIME_OUT. I have created a filter
> module. I'm creating a timer in filter headers:
>
> static ngx_int_t simple_timeout_filter_headers(ngx_http_request_t* request)
> {
> ngx_event_t* timeout_event;
>
> timeout_event = ngx_pcalloc(request->pool, sizeof(ngx_event_t));
> if (timeout_event == NULL)
> {
> return NGX_ERROR;
> }
>
> timeout_event->handler = simple_timeout_handler;
> timeout_event->data = request;
> timeout_event->log = request->connection->log;
>
> ngx_log_debug0(NGX_LOG_DEBUG_HTTP, request->connection->log, 0,
> "SIMPLE TIMEOUT TIMER START");
>
> ngx_add_timer(timeout_event, 3000); /* wait for 3 seconds */
>
> return next_header_filter(request);
> }
>
> Simple timeout handler looks like this:
>
> static void simple_timeout_handler(ngx_event_t* timeout_event)
> {
> ngx_log_debug0(NGX_LOG_DEBUG_HTTP, timeout_event->log, 0,
> "SIMPLE TIMEOUT TIMER END");
> }
>
> And it works if I issue a request, and wait for a timer to fire. If I issue
> several requests while the previous timer is already in progress, I get a
> SEGFAULT.

At least you don't remove the timer if the request completes
before the timer is triggered. This is enough to trigger a
segmentation fault.

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

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

Simple timeout module

donatasm May 20, 2015 01:03PM

Re: Simple timeout module

Maxim Dounin May 20, 2015 02:38PM

Re: Simple timeout module

Valentin V. Bartenev May 20, 2015 02:38PM

Re: Simple timeout module

donatasm May 21, 2015 04:41AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 123
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