ConcurrentModificationException in DispatcherServlet with asynchronous ApplicationEventMulticaster [SPR-17442] #21974
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
Jared Wiltshire opened SPR-17442 and commented
We are occasionally seeing a ConcurrentModificationException thrown from DispatcherServlet.initHandlerMappings(ApplicationContext context) due to the sorting of the handler mappings from two different threads (DispatcherServlet line 590 in 5.0.10).
I traced the cause of this back to our use of SimpleApplicationEventMulticaster with an asynchronous task executor.
What is happening is that FrameworkServlet.initWebApplicationContext() calls configureAndRefreshWebApplicationContext(cwac) which fires off a ContextRefreshedEvent. This results in onApplicationEvent(ContextRefreshedEvent event) being called from an executor thread which then calls onRefresh(event.getApplicationContext()). Further down in initWebApplicationContext() (FrameworkServlet line 557) it checks the boolean refreshEventReceived and calls onRefresh(wac) again from the main thread as there is no synchronization.
Affects: 5.0.10
Issue Links:
Backported to: 5.0.11
The text was updated successfully, but these errors were encountered: