<div dir="ltr"><pre style="white-space:pre-wrap;color:rgb(0,0,0)">> Hi,</pre><pre style="white-space:pre-wrap;color:rgb(0,0,0)">Thank you for your explanation.</pre><pre style="white-space:pre-wrap;color:rgb(0,0,0)">I added comments. Please check it one more time.</pre><pre style="white-space:pre-wrap;color:rgb(0,0,0)">>><i> On 23 Jul 2020, at 08:29, Sangdeuk Kwon <<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel">sangdeuk.kwon at quantil.com</a>> wrote:
</i>>><i>
</i>>><i> # HG changeset patch
></i>><i> # User Sangdeuk Kwon <<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel">sangdeuk.kwon at quantil.com</a> <mailto:<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel">sangdeuk.kwon at quantil.com</a>>>
</i>>><i> # Date 1595481798 -32400
></i>><i> # Thu Jul 23 14:23:18 2020 +0900
></i>><i> # Node ID 90e5ccf7c229322079ba1b61b4241ed69dfc09b2
></i>><i> # Parent 4f30f75dbdf33d6fae9e70086e0df5cbab7db027
></i>><i> During background update, nginx can't add "Range" header
></i>><i>
></i>><i> If the configuration is "slice enabled" and "proxy_cache_use_stale updating"
</i>>><i> and "proxy_cache_background_update on",
></i>><i> nginx can't get "$slice_range" value during background update.
></i>><i> nginx sends request to upstream without "Range" header.
></i>><i> The re-fetched content is saved by cache key of absent "$slice_range".
</i>>><i> So, nginx always serves stale content even though after re-fetching new content.
</i>>
> This is correct. The slice module does not work with background updates.
>
>><i>
></i>><i> slice 1k;
></i>><i> proxy_cache_use_stale updating;
></i>><i> proxy_cache_background_update on;
></i>><i> proxy_cache_key "$host$uri[$slice_range]
></i>><i>
></i>><i> diff -r 4f30f75dbdf3 -r 90e5ccf7c229 src/http/modules/ngx_http_slice_filter_module.c
</i>>><i> --- a/src/http/modules/ngx_http_slice_filter_module.c Tue Jul 21 20:34:29 2020 +0300
</i>>><i> +++ b/src/http/modules/ngx_http_slice_filter_module.c Thu Jul 23 14:23:18 2020 +0900
</i>>><i> @@ -400,9 +400,12 @@
</i>>><i> ngx_http_slice_loc_conf_t *slcf;
</i>>><i>
</i>>><i> ctx = ngx_http_get_module_ctx(r, ngx_http_slice_filter_module);
</i>>><i> + if (r->background && r != r->main && r->main != r->parent) {
</i>>><i> + ctx = ngx_http_get_module_ctx(r->parent, ngx_http_slice_filter_module);
</i>>><i> + }
</i>>
> Here you’re trying to get the parent request’s context to access the slice range.
> But slice range is being constantly updated. So there’s no guarantee that you get
> the right slice range.
> The right solution would be to pass the slice range to the background update
> subrequest as an argument or a part of uri. But that does not seem to be possible
> within the current background update implementation. Probably there’s a way to save
> and then access the right slice using njs.
></pre><pre style="white-space:pre-wrap;color:rgb(0,0,0)">The posted requests are saved as below order in r->main->posted_requests.<br>Subrequest of background update is executed next to same slice request before next slice request.<br>Background update's r->parent refers same slice request.<br>So, r->parent's ngx_http_slice_ctx_t has correct "Range" value for background update.<br><br>r: slice #1<br>r->main->posted_requests: -> background update request (slice #1) -> next slice request (slice #2)<br><br>r: background update request (slice #1) (r->main=slice #1, r->parent=slice #1)<br>r->main->posted_requests: -> next slice request (slice #2)<br><br>r: slice #2<br>r->main->posted_requests: -> background update request (slice #2) -> next slice request (slice #3)<br><br>r: background update request (slice #2) (r->main=slice #1, r->parent=slice #2)<br>r->main->posted_requests: -> next slice request (slice #3)<br><br>r: slice #3 (if no need background update)<br>r->main->posted_requests: -> next slice request (slice #4)<br><br>r: slice #4<br>r->main->posted_requests: -> background update request (slice #4) -> next slice request (slice #5)<br><br>r: background update request (slice #4) (r->main=slice #1, r->parent=slice #4)<br>r->main->posted_requests: -> next slice request (slice #5)<br><br><br><br>But, in slice #1 case, "Range" value of ctx is already updated to next value (slice #2) when it's created.<br>So, background update of slice #1 can't use r->parent's ctx.<br><br>When user request has "Range" header(only one slice case), background update can generate "Range" value by "Range" header.<br><br>"r->main == r->parent" condition is for slice #1 and user request has "Range" header(only one slice case)<br>"r->main != r->parent" condition is for slice #2, slice #3, and ...</pre><pre style="white-space:pre-wrap;color:rgb(0,0,0)">>><i>
</i>>><i>
</i>>><i> if (ctx == NULL) {
</i>>><i> - if (r != r->main || r->headers_out.status) {
</i>>><i> + if ((r != r->main && !r->background) || r->headers_out.status) {
</i>>><i> v->not_found = 1;
</i>>><i> return NGX_OK;
</i>>><i> }
</i>>
> Here you are creating a new ctx for the background update subrequest,
> which suggests that you want to update the entire response rather that
> only one slice.
></pre><pre style="white-space:pre-wrap;color:rgb(0,0,0)">It's created when slice #1 and user request has "Range" header(only one slice case)
>><i> _______________________________________________
</i>>><i> nginx-devel mailing list
</i>>><i> <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel">nginx-devel at nginx.org</a>
</i>>><i> <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a></i></pre></div>