-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
blocking netty thread causes a calling http client to hang #2593
Comments
Please upload sample application(s) to reproduce the issue. Without knowing more specifics I don't know where I would start to investigate your issue |
I will provide an example tomorrow, I cannot reproduce it on my windows machine. |
Hi @jameskleeh i could finally reproduce the issue in a clean project based on the 'creating-your-first-micronaut-app' tutorial project. Tested on Mac OS Please:
Test setup:
I found that suspending the request handler thread must be within the Http Filter. Suspend within the @controller will not trigger this behavior. |
I don't see anything here that is a bug. You should never block the event loop. You can move blocking operations onto a separate thread pool.
Likely because the controller isn't being executed on the event loop |
Hi @jameskleeh, thanks for the quick response. Now carefully re-reading the documentation it does tell that I should use the filter in a non-blocking way (https://docs.micronaut.io/latest/guide/index.html#_writing_a_filter). Problem was that I expected that the Wouldn't it be possible to execute the If I may suggest it would be great to highlight in the documentation that any blocking operation within a |
@pkonyves If you think the documentation can be made more clear, a PR would be welcome It would not be desirable to offload the filter execution. Given filters are reactive in nature it should be assumed that blocking operations should be offloaded. |
@jameskleeh thx, I will! |
I have some REST endpoints implemented in micronaut (service A). One of the endpoint calls another service (service X) using a java.net.http.HttpRequest. Service X may have a long response time, e.g. minutes. Once this call is in progress, I am regularly calling service A (from curl) and every once in a while it just hangs.
For me it looks like that once service A is in the calling to service X, it's holding one of the nioEventLoopGroup-1-x threads waiting for the blocking operation to finish. Subsequent calls to service A endpoints will be handled by different nioEventLoopGroup-1-# threads in a round-robin fashion. But once the blocking nioEventLoopGroup-1-x would have the turn, the request just hangs. This behavior is deterministic, seeing from the logs which nio thread is handling the request, I see when the blocked thread has the turn, the call to service A just hangs. Then I make a new request to service A, which will respond perfectly. If given the netty thread pool size of 5 and 1 netty handler thread is blocked, then I will have every 5th request to service A hanging.
In my opinion Micronaut should never try to assign an http request handling to a thread that is blocked but apparently this is happening.
Steps to Reproduce
Create two REST endpoints.
Thread.sleep(10*60*1000)
, call it/blocking
/ok
micronaut.server.netty.worker.threads: 3
make some calls to above endpoints from curl
Expected Behaviour
curl http://localhost:8080/blocking
ctrl + C
curl http://localhost:8080/ok
->curl http://localhost:8080/ok
->curl http://localhost:8080/ok
->Actual Behaviour
curl http://localhost:8080/blocking
curl http://localhost:8080/ok
->curl http://localhost:8080/ok
->curl http://localhost:8080/ok
->Environment Information
The text was updated successfully, but these errors were encountered: