-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
js_body_filter sends empty body response when buffering is on #411
Comments
Hi @gnomeby, Is it still an issue for you? |
Not for me. I'm sending X-Accel-Buffering=yes to disable proxy_buffering in case when output is not text/html. But I think this is the bug in general. |
Hit this one on our servers this week. When using a simple body filter like this: function my_simple_body_filter(r, data, flags) {
r.warn("got " + data.length + " chars, flags: " + flags.last);
r.sendBuffer(data, flags);
} Fetching the resource (around 1600kB js) with curl from localhost over its own ip, gets the following log (OK):
Fetching the same url from another host over the same ip, gets the following log (FAIL):
Which results in curl waiting for the remaining bytes (1726981 - 80389) until it times out, when nginx thinks it already has delivered the full response. Looking like this (received bytes don't match exactly as this was before i reproduced it locally):
Repeated logs of 4096 were replaced by ... . To me it looks like if nginx begins buffering to a temporary file the stream of chunks of data to the body filter is interrupted and doesn't get all the data it needs. Tested with nginx 1.22.0 from dockerhub (https://hub.docker.com/layers/nginx/library/nginx/1.22/images/sha256-813c400b452834cea3f6b3231168a64a4310369ba9f0c571b2bd11c437d4284a?context=explore) to be close to the installation on our server where we noticed this first. As a workarround in my real body filter i mark all responses that i do not need to change with r.done as soon as possible, which prevents the problem on our servers for now: function my_simple_body_filter(r, data, flags) {
if (r.variables.my_condition_matches) {
r.sendBuffer(data.replace(/foo/g,"bar"), flags);
} else {
r.sendBuffer(data, flags);
// if any data chunk is received where the rewrite condition is not met, we can pass all the chunks for this
// request without any filtering. so we are done for this request.
r.done();
}
} |
Hi @ap-wtioit, Thank you for the report, will look into it. |
Having same issue, is it due to content length changing? As seen in this issue, if i delete the header for content length there is no issue:
|
@t0mtaylor tested deleting the
As you can see in the curl progress output and wc -l we are nowhere near retrieving the full 1686k i get when proxy buffer temporary file is not created (e.g. when running curl on the same host)
Deleting the header only gets rid of the side effect that curl times out but the js file delivered is still garbage after most of it's contents are missing. |
Hello.
I have a django application. Let's assume I have empty django project created by:
On nginx side I have the following configuration:
utils.js
So when I request resource with Content-Type!=text/html I get normal headers and empty body.
If I comment js_header_filter and js_body_filter - everything is OK.
If I comment proxy_cache_use_stale WGET just freezes on getting body.
If I uncomment "proxy_buffering off;" - everything is OK.
nginx 1.20.1
njs 0.6.1
The text was updated successfully, but these errors were encountered: