I've experimented with slightly updated SessionAsyncListenerTest from TCK. Test is checking whether SessionScoped is active during calls to AsyncListener methods (in this case only onComplete). I've found out that this doesn't work on Tomcat nor on Jetty.
It's following scenario on tomcat:
thread-1 - request initialized in org.jboss.weld.servlet.WeldInitialListener#requestInitialized
|
thread-2 - Tomcat AsyncContextImpl call asyncListeners
|
thread-2 - request destroyed in org.jboss.weld.servlet.WeldInitialListener#requestDestroyed
|
thread-3 - request initialized in org.jboss.weld.servlet.WeldInitialListener#requestInitialized
|
thread-3 - request destroyed in org.jboss.weld.servlet.WeldInitialListener#requestDestroyed
|
Following scenario on Jetty:
thread-1 - request initialized in org.jboss.weld.servlet.WeldInitialListener#requestInitialized
|
thread-1 - request destroyed in org.jboss.weld.servlet.WeldInitialListener#requestDestroyed
|
thread-2 - call async listeners from org.eclipse.jetty.server.AsyncContinuation#doComplete
|
thread-3 - request initialized in org.jboss.weld.servlet.WeldInitialListener#requestInitialized
|
thread-3 - request destroyed in org.jboss.weld.servlet.WeldInitialListener#requestDestroyed
|
thread-1 - request initialized in org.jboss.weld.servlet.WeldInitialListener#requestInitialized
|
thread-1 - request destroyed in org.jboss.weld.servlet.WeldInitialListener#requestDestroyed
|
... followed by chaotic initialize/destroy calls in various threads
|
This does work on Undertow, because it does this before calling asyncListeners in AsyncContextImpl. This is done with help of ServletRequestContext if I understand it correctly.
|