-
Notifications
You must be signed in to change notification settings - Fork 114
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
body content sometimes (!) missing in async content handler #299
Comments
Hi, Filler. |
Hi xfeep, I just tested it out and it's in both cases (contains body/misses body) a SequenceInputStream:
Best regards, Andreas |
Hi, Andreas, |
Hi xfeep, we never had problems with thread pool mode and NGINX and we are using this configuration quite long already. But I will keep an eye on it after your input. The result is interesting: In NOT successful cases the .available() is 401 and later 0. In successful cases (so the content can also be read in run()) it is 1241 in both methods, so before starting the thread and inside the thread. Summarized: When the stream is already at 1241 it is also possible to read it later. If it's not (401) it's empty later (0). Hope it helps a bit in investigating. I keep my setup as it currently is for further testing. |
PS: We are not using "jvm_workers" (so the default of 0 should be used). The thread name comes from the thread pool executor I use in my class NginxJavaRingHandler for handling the parallel request: Constructor: Usage: ...so this is simply internally in my class to be able to handle the hijacked requests in parallel. |
Hi Andreas, |
PS: java.io.SequenceInputStream.available() only returns the first stream's available(). If there're serveral chunks in the body the value which available() returns is not always the total length of the body. So both .available() is 401 and .available() is 1241 are OK. |
Thank you for your explanation and clarification. I adjusted my implementation now that it reads the body before going starting into the thread. The body will be handed over in the constructor of the same. It's less threaded in the end, but working stable. Thanks again! |
@afiller Hi Andreas, Please try a workaround way for better performance. // get a user mananged body reference
Inputstream umbody = (Inputstream)MiniConstants.BODY_FETCHER.fetch(nginxRequest.nativeRequest(), null);
// access umbody in another thread and then close it.
... I've also created a related issue for the future enhancement about the hijack API. |
What happens:
I have a Java content handler implementing "NginxJavaRingHandler" which has a async setup using a thread, channel and hijack. Source below. When the NGINX endpoint is called from some sources (the problem does not exist with all sources) with content in a POST request, the body (InputStream) is sometimes (!) empty, when accessing it from the thread. It's always full, wenn I read out the body before starting the thread with the channel. The content of the input stream seems to be cleared too early and I don't know why?!
I of course know, that the input stream cannot be read twice. The source below only shows the two positions where I read the in the input stream using Commons-IO, but I also tried it with Vanilla Java.
Thanks for helping!!!
PS: The "val" and "@cleanup" are from lombok.
My configuration:
Environment:
NGINX:
JAVA (excerpt, relevant parts):
The text was updated successfully, but these errors were encountered: