Welcome! Log In Create A New Profile


internal redirect and module context

January 21, 2022 07:10PM
I have a question related to internal redirect, I am hoping someone from
this forum can clarify. The email is a bit long since I wanted to provide
enough background for my situation.

In my module, I am creating my module context and saving some state. Some
of this state is allocated using ngx_palloc. I am releasing this memory by
adding a pool clean up handler.

In my module, for certain requests I am doing an internal redirect. My code
for redirect looks something like this:

ngx_http_internal_redirect(r, &new_uri, &r->args);
ngx_http_finalize_request(r, NGX_DONE);

According to the documentation

it says, on calling internal_redirect, the module context will be erased to
avoid inconsistencies. It also says, the processing returns to the
NGX_HTTP_SERVER_REWRITE_PHASE. To understand the behavior better, I
attached a debugger and added a breakpoint after the above two lines. When
the debugger stopped at my breakpoint, my module context still seems to be
valid. I added a second breakpoint in my rewrite-handler and allowed the
debugger to continue. Now when the debugger stopped at the second
breakpoint, my module context was erased which seems consistent with the

So my question is, if my context is erased, what happens to the memory I
allocated before my module invoked the internal redirect call? I put a log
statement in my cleanup function and I observed that it is getting invoked
only once at the end of the request processing. It is not getting called
when my context is erased after an internal redirect. Since I need my
context data after redirection, do I reallocate and recreate it? Since my
clean up code is getting called only once. Would this lead to a memory leak
if I reallocated after the internal redirect call because I'd be allocated
once before redirect and once after redirect. Any help or clarification in
this regard is greatly appreciated.

nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

internal redirect and module context

dnj0496 162 January 21, 2022 07:10PM

Re: internal redirect and module context

Maxim Dounin 40 January 22, 2022 12:22AM

Re: internal redirect and module context

dnj0496 340 January 22, 2022 05:22AM

Re: internal redirect and module context

Maxim Dounin 31 January 22, 2022 02:10PM

Re: internal redirect and module context

dnj0496 49 January 22, 2022 02:42PM

Sorry, you do not have permission to post/reply in this forum.

Online Users

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