Skip to content

Deadlocks with DeferredResult timeout handling on Tomcat [SPR-10485] #15118

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

Closed
spring-projects-issues opened this issue Apr 24, 2013 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Apr 24, 2013

Peter De Wachter opened SPR-10485 and commented

I'm experiencing deadlocks and other bugs when calling DeferredResult#setResult while that deferred result's timeout handler is running. This is on Tomcat 7.0.39. I'm using the following code to reproduce this.

@Controller
public class TestController {
    private DeferredResult<String> deferred;

    static class DoSomethingUseful implements Runnable {
        public void run() {
            try { Thread.sleep(2000); } catch (InterruptedException e) { }
        }
    }

    @RequestMapping(value="/test/start")
    @ResponseBody
    public DeferredResult<String> start() {
        deferred = new DeferredResult<String>(4000L, "timeout\n");
        deferred.onTimeout(new DoSomethingUseful());
        return deferred;
    }

    @RequestMapping(value="/test/stop")
    @ResponseBody
    public String stop() {
        deferred.setResult("result\n");
        return "ok\n";
    }
}

The start method creates a DeferredResult with a 4 second timeout. To make the bug easy to reproduce, it has an onTimeout handler which will sleep for 2 seconds. The stop method will set a value for the DeferredResult. The code seems correct to me: the DeferredResult documentaion states that "the application can produce the result from a thread of its choice", and also that setResult can be called on an DeferredResult that's already expired.

To reproduce the bug, try something like this:

curl http://localhost/test/start & sleep 5; curl http://localhost/test/stop

On Tomcat using the APR connector, this will deadlock. On Tomcat using the NIO connector, this will sometimes (not consistently) never answer the start request and return the "timeout\n" string as a result of the stop request.


Affects: 3.2.2

Reference URL: spring-attic/spring-framework-issues#48

Issue Links:

Referenced from: commits db596d2, 25701ef

@spring-projects-issues
Copy link
Collaborator Author

Peter De Wachter commented

Added link to spring-framework-issues pull request.

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

This should now be fixed. Thanks for the very helpful repro project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants