Welcome! Log In Create A New Profile

Advanced

Launch subrequest before filter gets called

Posted by PsyKro 
Launch subrequest before filter gets called
November 29, 2018 05:29AM
Dear Nginxers,

I previously wrote a post which got no response, after rereading it, it was in fact not clear at all... Mainly due to a misunderstanding on my side! This is the reason why i prefer starting a new thread to avoid confusions.

I came up with a solution where I have a filter which makes subrequests to various upstreams. It afterwards aggregates the responses along with the main request, manipulates the response and then calls the next filter with this. This is working nicely, all subrequests are sent in parrallel, so far so good...

However, this filter gets called only when we start receiving some data for the main request (which is also an upstream). This is not very efficient because if this upstream is slow, then the whole process is delayed!

In order to avoid this, how should i proceed ?
* Do i have to move my filter to a module hooked on CONTENT phase ? In that case, how to retrieve the subrequest responses, would it delay the filtering ?
* Trick the Content phase, so that filter is called immediately and the main request upstream is called by a subrequest ? (Yeah that's ugly !)

Thanks for your help,

kR
Re: Launch subrequest before filter gets called
December 03, 2018 10:08AM
Dear members,

To achieve my usecase, i have created a module that launches two subrequests to different upstreams. I then retrieve the body of those subrequests' responses and put them into a single output chain. Which i forward to a dedicated filter.

This works sometimes, and sometimes not ... Indeed, NGINX worker regularly crashes during request finalization, the reason for this is that the request pool is NULL (as many of the ngx_http_request_t attributes). I suspect it has been freed by some way but i don't get why it doesn't happen everytime

If you have any ideas ?

Thanks,

kR
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 103
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready