Comments (9)
Hi Andreas,
Thank you very much. You provided very useful information.
Now I can confirm that it will be a problem if we read body out of the sope of handler.invoke(req) because body will be closed at the end of handler.invoke(req).
So if your thread runs quickly before the end of handler.invoke(req) you can read the body successfully otherwise you will get an closed inputstream.
In the futerue version I will consider the tradeoff between resource leak risk and flexibility.
from nginx-clojure.
Hi, Filler.
Could you please tell us what value is bodyInputStream.getClass() when the bodyInputStream is missing?
There're three kinds of bodyInputStream. The first is FileInputStream when Nginx uses tmp body file. The second is NativeInputStream and the last is SequenceInputStream where stores a list of NativeInputStream.
from nginx-clojure.
Hi xfeep,
thank you for your reply and - by the way - for your great project. The library is so amazing and I love using it, it fills such an important gap by realising dynamic NGINX redirects.
I just tested it out and it's in both cases (contains body/misses body) a SequenceInputStream:
2023-08-17 09:59:00[warn][21190][pool-1-thread-1]>>>java.io.SequenceInputStream
2023-08-17 09:59:00[warn][21190][pool-1-thread-1]<<<<
2023-08-17 09:59:02[warn][21186][pool-1-thread-1]>>>java.io.SequenceInputStream
2023-08-17 09:59:02[warn][21186][pool-1-thread-1]<<<<{"event": {"event_timestamp_ms": 1692259142008, "product_id":....
Best regards,
Andreas
from nginx-clojure.
Hi, Andreas,
I'm glad to see this library is useful to you.
Please show the two values of bodyInputStream.available(). The first one is got at ExternalRESTCallHandler.invoke(request). The second one is got at InvocationHandler.run().
BTW I find thead pool mode is used (viz. jvm_workers > 0) and requst.hijack(..) / request,handler().hijack(..) is used together with thead pool mode. In most general cases requst.hijack(..) is used with plain mode to avoid blocking nginx.
from nginx-clojure.
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.
from nginx-clojure.
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:
ExecutorService executorService = Executors.newCachedThreadPool();
Usage:
// Run thread in thread pool executor
executorService.execute(new InvocationHandler(nginxRequest, channel));
...so this is simply internally in my class to be able to handle the hijacked requests in parallel.
from nginx-clojure.
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.
from nginx-clojure.
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!
from nginx-clojure.
@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.
from nginx-clojure.
Related Issues (20)
- java.lang.VerifyError happens when use mysql jdbc 8.0.32 on jdk19 + nginx-clojure 0.6.0 HOT 1
- NginxSharedHashMap.atomicAddLong return wrong value when value is very large
- remote debug not work on jdk 19 with coroutine mode
- Directives for jvm int/exit handler properties
- Enable coroutine context for invoking config method of a handler in coroutine mode
- Rewrite handlers can add/update request headers
- Dispatch incoming request to a jsp and set attribute HOT 2
- Support load-balancing handler
- Add new handler types to better support spring and spring boot
- nginx-clojure-embed need be compiled with more built-in nginx c modules HOT 1
- Proxy server error jvm may be mad for wrong options! See hs_err_pid****.log for detail! HOT 9
- How to debug/test nginx-clojure handlers
- StringFacedJavaBodyFilter/StringFacedClojureBodyFilter need auto decompress body when the body is compressed.
- java.lang.RuntimeException: can not create nginx handler for name HOT 4
- CVEs in maven artifact HOT 3
- nginx 1.25.0 build error HOT 3
- Support for random user ID in containerised environments - startup failure due to POSIX method getpwuid failure
- Enhance hijack API to give users a chance to manage the closing of request body
- Running Nginx Clojure in Docker prompts: jvm may be mad for wrong options HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nginx-clojure.