Non blocking delay in header filters

Ava Hahn a.hahn at f5.com
Thu Apr 20 16:46:43 UTC 2023


Hello All,
I am currently implementing a response header filter that triggers one or more subrequests conditionally based on the status of the parent response.

I want to introduce some delay between the checking of the response and the triggering of the subrequest, but I do not want to block the worker thread.

So far I have allocated an event within the main request's pool, added a timer with my desired delay, and attached a callback that does two things.

  1.  triggers a subrequest as desired
  2.  proceeds to call the next response header filter

In the meantime, after posting the event my handler returns NGX_OK.

This is not working at all. Shortly after my filter returns NGX_OK the response is finalized, and the pool is deallocated. When the timer wakes up a segfault occurs in the worker process (in ngx_event_del_timer). Even if I allocate the event in a separate pool that outlives the request it is still not defined what happens when I try to trigger a subrequest on a request that has been finalized.

My question is how can I make the finalization of the request contingent on the associated/posted event being handled first?

OR, is there another facility for implementing non blocking delay that I can use?

Thanks,
Ava

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20230420/8c385776/attachment.htm>


More information about the nginx-devel mailing list