Implementing a non-blocking delay between request and response

Tronman nginx-forum at
Fri Jan 15 17:43:17 MSK 2010

Hi folks, thanks for your responses! As a quick note, I've been using ngxin 0.7.64

Marcus Clyne wrote:
>As a side-note here, this should have included returning a failure - you
>would have got a segfault on failure otherwise

For sure, I'm just experimenting for now, not too much error handling.

>You should use ngx_add_event () here instead of allocating the space for
>the event struct directly.

I spent some time looking at ngx_event.h, but can't figure out the semantics of that call. It doesn't look like it actually allocates space for the event that I can tell, so I still have to pcalloc. Even then, I tried ngx_add_event(wakeupFromSleep, NGX_ONESHOT_EVENT, 0) (and READ, WRITE events), but it still just seg faults. 

>If you do nothing else here, then your request will return immediately.
>(Check out the code in ngx_http_finalize_request() to understand why.)


>is one way that should prevent it from returning the first time.

Since I'm using 0.7.64 (sorry for not mentioning that sooner), my ngx_http_request doesn't have a count element. Is there something similar to prevent return in 0.7.64?

Also, I know ngx_http_finalize_request() never even gets called after I add the timer and the request returns. So I don't see how it could be causing it to return immediately. 

>You should add a ngx_del_event() too here.

Yep, but I have to figure out how to use add event first.

>By the way, this question is probably better asked in the nginx-devel
>mailing list rather than the main one.

Sorry, it can be tricky to figure out where something should go, and I don't have the mailing list set up.
Thanks for the CC agentzh.

agentzh wrote:

>Heh, it reminds me of the echo_sleep and echo_blocking_sleep
>directives in the ngx_echo module:

I took a look at that module, and it does seem somewhat similar, except I want the sleep to be specifiable from the code, not the configuration file. I'm not sure what's being done differently to implement it that I'm not doing.

Thanks again.

Posted at Nginx Forum:,41283,41665#msg-41665

More information about the nginx mailing list