0.25.2 generates a 409/Conflict responses with Async results
See original GitHub issueHi team,
I discovered a regression after upgrading from Spring Boot 2.1.6 to 2.1.7 and especially with the upgrade from hateoas 0.25.1 to 0.25.2.
We have a controller defined like this (note the async result)
@RestController
@RequestMapping("/api/foo")
@ExposesResourceFor(FooStuffs.class)
public class FooStuffsController {
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public Future<FooStuffs> getFooFromToDate(@RequestParam("fromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fromDate,
@RequestParam(value = "toDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate optionalToDate) {
....
}
Which was working before:
2019-10-18 21:51:54.386 DEBUG 7242 --- [ XNIO-1 task-3] o.s.web.servlet.DispatcherServlet : "ASYNC" dispatch for GET "/api/foo?fromDate=2019-10-01&toDate=2019-10-18", parameters={masked}
2019-10-18 21:51:54.390 DEBUG 7242 --- [ XNIO-1 task-3] s.w.s.m.m.a.RequestMappingHandlerAdapter : Resume with async result [FooStuffs{fromDate=2019-10-01, toDate=2019-10-08, foo=[]}]
And now it fails with a Conflict / 409 http error:
2019-10-18 21:55:30.858 DEBUG 7552 --- [ XNIO-1 task-3] o.s.web.servlet.DispatcherServlet : "ASYNC" dispatch for GET "/api/foo?fromDate=2019-10-01&toDate=2019-10-18", parameters={masked}
2019-10-18 21:55:30.861 DEBUG 7552 --- [ XNIO-1 task-3] s.w.s.m.m.a.RequestMappingHandlerAdapter : Resume with async result [java.lang.IllegalStateException: Cannot ask for request attribute - request is not active anymore!]
Digging a bit (thanks @bclozel @snicoll) I found that it is a side effect of PR #749
The problem is about the cache which is using RequestAttributes.SCOPE_REQUEST
but it’s not active because of the async and thus we get the IllegalStateException
I am not sure if hateoas is supposed to support Async results (I didn’t find any doc to deny or validate it). Let me know if I can help more @odrotbohm @gregturn
NOTE: I didn’t try with 1.x but as far as I can see the code of UriComponentsBuilderFactory
didn’t change.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:14 (7 by maintainers)
@gregturn I found the issue \o/ and I am happy to share that it’s not bug in hateoas !!!
I found that a previous developer implemented a workaround to allow hateoas to work with Async when it was not supported. For this he wrote a specific config for the Servlet Dispatcher … While it was explained in the class comment the name of the Config amongst all others never caught my eye. Removing it is solving my issue. The bug was in our app because of the conflict between the workaround and the fix done in 0.25.2 … I am now safe to upgrade
Seeing as we have no test cases surrounding async Spring MVC behavior, I’d like to work on one so we have somewhere to go. First and foremost, I want to see if this issue exists on the
master
branch, and then work from there.If it does, we patch it and then assess backporting the fix to earlier versions.