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

WebAsyncManager should cancel task thread on timeout [SPR-15852] #20407

Closed
spring-issuemaster opened this Issue Aug 7, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Aug 7, 2017

Jordi Puigsegur opened SPR-15852 and commented

Hi,

We are implementing a REST service with and endpoint that does some processing, part of it being in a database transaction. We would like to use WebAsyncTask to run this task in a separate thread and establish a timeout. However, we find that when the timeout has elapsed the service returns the corresponding Timeout Exception but the thread continues to work finishing the database transaction while we would like it to fail and perform a rollback.

We understand that the way to control it is by honoring isInterrupted() inside our code before committing the transaction. This way the executor thread will know that the timeout has exceeded and will exit with an exception performing a rollback. However it seems that the thread is not interrupted.

Which is the right way to do this? Is the spring platform supposed to call .interrupt() when the timeout is activated or we have to do this ourselves?

Thanks,
Jordi.


Affects: 4.3.5

Reference URL: https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncTask.java

Referenced from: commits 681ced8, 8b7a670

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Aug 8, 2017

Juergen Hoeller commented

Indeed, interruption is the way to go here. We can't interrupt the task thread directly since we're dispatching to it behind an Executor abstraction; however, we should be able to cancel the returned Future with cancel(true) which leads to interruption of the target thread.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Aug 8, 2017

Jordi Puigsegur commented

Ok. Thanks. I'll keep an eye on this thread.
So far we have implemented the following workaround: The runner callable stores the thread in a final array which is shared with the timeout callable. The timeout callable then can interrupt the thread on the timeout. When this is solved we will be able to remove this code.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Aug 16, 2017

Rossen Stoyanchev commented

I've added a call to cancel the Future. Feel free to give it a try to confirm it works in your scenario.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Aug 16, 2017

Jordi Puigsegur commented

Thanks,
As soon as we can we will try to test it and confirm it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.