Skip to content
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

nginx connection hangs with a NginxJavaHeaderFilter when proxy_buffering is off #209

Closed
mengzheng opened this issue Apr 23, 2018 · 3 comments

Comments

@mengzheng
Copy link

mengzheng commented Apr 23, 2018

The nginx connection hangs until timeout for the following nginx configuration:
header_filter_type 'java';
header_filter_name 'MyHeaderFilter'
proxy_http_version 1.1;
proxy_buffering off;

Note the curl output in verbose mode shows:

Transfer-Encoding: chunked

It works fine if I remove the header filter.

It also works fine if I make any of the following changes:

  1. change proxy_buffering to on
  2. change proxy_http_version to 1.0
  3. set Content-Length in response header

Note if I change proxy_http_version to 1.0 or set Content-Length in response header, the transfer encoding is no longer trunked. I am not sure this is related to the hanging issue. Even with trunked transfer encoding, it works fine if I change proxy_buffering to on.

For testing purpose, my filter class is simply:

public class MyFilter implements NginxJavaHeaderFilter {
@OverRide
public Object[] doFilter(int status, Map<String, Object> request, Map<String, Object> responseHeaders) throws IOException {
return Constants.PHASE_DONE;
}
}

My nginx version is 1.12.2 and my nginx-closure version is 0.4.5. You should be able to reproduce the issue easily.

This is a blocking issue for me as my customers use the above configuration for streaming large amount of data. Thanks for your help!

Jason

@mengzheng mengzheng changed the title nginx connection hangs with a NginxJavaHeaderFilter nginx connection hangs with a NginxJavaHeaderFilter when proxy_buffering is off Apr 24, 2018
@xfeep
Copy link
Member

xfeep commented Apr 24, 2018

@mengzheng Another workaround is to use default mode with thread pool disabled. e.g

# jvm_worker xx;

@mengzheng
Copy link
Author

@xfeep It worked. This is probably the best workaround. Thanks!

A few questions:

  1. I use nginx as reverse proxy in front of the Rest Service. I am not familiar with Coroutines support. If I cannot use thread pool with proxy buffering off, can I use coroutines support instead to handle slow I/O operations? Does "proxy_buffering off" work well with coroutines support?

  2. The service sends stream data to the client with chunked Transfer-Encoding. I noticed that the header filter is only called once. It is called per request, not per chunk. Is that expected behavior?

  3. Assume the service streams the data to the client over a period of time. When the filter is invoked, the status is 200. But the streaming fails and exits after some time and sets status to 500. How can the header filter be invoked again with 500 status?

@xfeep xfeep added this to the 0.5.1 milestone Nov 11, 2019
xfeep added a commit that referenced this issue Nov 11, 2019
@xfeep
Copy link
Member

xfeep commented Nov 11, 2019

@mengzheng Sorry for so late reply. Commit ee7258d fixed this issue and we'll release this fix with 0.5.1.

Answers:

  1. proxy_buffering off should work with coroutines suppport
  2. Header filter is called per request, not per chunk.
  3. Once headers are sent we can not modify them which include status code.

@xfeep xfeep closed this as completed Nov 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants