Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Bad __context set in WebAppContext.start sequence with respect to ENC setup

We are embedding Jetty and today we noticed the following not quite trivial bug in Jetty's start handling for Web apps.

This bug was observed on Jetty 8.1.4 and as far as I can tell the relevant code has not changed since then. It happens when you start a WebAppContext from within a running Web app, i.e. while processing a request. In our scenario, a Web app may be started on-demand and the trigger to do so may occur while in a Web app.

I checked with Jetty 6.1.22 (old integration) and it works ok there - I did not debug it all the way through to see why it works there and not in 8.1.4.

Here is what happens:

When calling WebAppContext.start() you end up in WebAppContext.doStart() which has this control flow:


In preConfigure, eventually EnvConfiguration.preConfigure(<context>) is called and that is setting up the JNDI ENC.

And here is where ContextFactory comes into the game:

When looking for the class loader to identify a "java:comp" ENC from, ContextFactory.getObjectInstance first consults ContextHandler.getCurrentContext(). Only if that returns null, the current thread's context class loader is considered.

However, the switch of Jetty Contexts in ContextHandler is done in ContextHandler.doStart(), i.e. only after the call to preConfigure() in WebAppContext.doStart().

Now, if you are not in a Web App and you want to start a WebAppContext and the current thread's context classloader is set, then ContextHandler.getCurrentContext()==null and you get an ENC for the new Web App as expected.

But if you are currently processing a Web app request, then ContextHandler.doScope will have set that Web app's context and ContextHandler.getCurrentContext()!=null and ContextFactory will try to create an ENC for a loader that already has one and you get:

Caused by: javax.naming.NamingException: This context is immutable; remaining name 'env' at org.eclipse.jetty.jndi.NamingContext.createSubcontext( at org.eclipse.jetty.jndi.NamingContext.createSubcontext( at at at org.eclipse.jetty.webapp.WebAppContext.preConfigure( at org.eclipse.jetty.webapp.WebAppContext.doStart( at org.eclipse.jetty.util.component.AbstractLifeCycle.start(

Please let me know, if there is some way of getting around this. Hope there was sufficient details and sorry for the complex case.


Back to the top