-
1. Re: WELD-000225 warning in Tomcat 7, but servlets are synchronous!
mkouba May 7, 2015 10:44 AM (in response to chrisjr)Hi Chris,
could you provide more info about your application? E.g. what other technologies are used. We've also observed this kind of issue with server push technologies (see for example WELD-1704). Anyway, these warnings should not imply a memory leak in the sense that the information is always overwritten when the thread is reused by Weld.
-
2. Re: WELD-000225 warning in Tomcat 7, but servlets are synchronous!
chrisjr May 7, 2015 11:05 AM (in response to mkouba)Well, the technology stack is:
- WELD 2.2.11.Final
- Tomcat 7.0.59
- Resteasy 3.0.11.Final
- JDK7
- Logback 1.1.3
- Jackson 2.4.5
- Codahale metrics 3.0.2 with Librato servlet
- Hibernate Validator 5.1.3.Final
- Scala 2.9.2 (Don't ask! I don't want it, but can't remove it!)
(more or less). I don't use any asynchronous requests in my application, but I did find a couple of home-grown logging filters for urlPatterns="/*" which had been declared with asyncSupported=true. These seem (to me) to be likely candidates for these WELD-000225 warnings as they weren't accompanied by any other application-related log messages.
-
3. Re: WELD-000225 warning in Tomcat 7, but servlets are synchronous!
chrisjr May 8, 2015 5:21 AM (in response to mkouba)I disabled those filters' asynchronous support via web.xml, but am still seeing an occasional "Bean store leak" warning. So I'm out of ideas here.
Anyway, these warnings should not imply a memory leak in the sense that the information is always overwritten when the thread is reused by Weld.
To be clear: doesn't the bean store contains fully-constructed beans which have not had their @PreDestroy handlers etc invoked yet? Which would in turn imply that these beans will not be destroyed correctly when the thread-local variable is overwritten either.
BTW, if this forum is running on JBoss then it's a terrible JBoss advertisement...
-
4. Re: WELD-000225 warning in Tomcat 7, but servlets are synchronous!
mkouba May 11, 2015 3:42 AM (in response to chrisjr)I disabled those filters' asynchronous support via web.xml, but am still seeing an occasional "Bean store leak" warning. So I'm out of ideas here.
AFAIK the only way to put the request into asynchronous mode is to call
ServletRequest.startAsync()
. So if you don't start async in your filter, it's not the cause. I see RESTEasy 3 in your stack. Do you use asynchronous processing capabilities in JAX-RS 2.0?To be clear: doesn't the bean store contains fully-constructed beans which have not had their @PreDestroy handlers etc invoked yet? Which would in turn imply that these beans will not be destroyed correctly when the thread-local variable is overwritten either.
It depends on the scope of a bean. For
@SessionScoped
it shouldn't be a problem - bean instances are destroyed outside the servlet request lifecycle, duringHttpSessionListener.sessionDestroyed()
invocation. For@ConversationScoped
this shouldn't be a problem either - conversation cleanup is performed for every request. Unfortunately, for@RequestScoped
beans this is a problem and bean instances are not destroyed correctly.BTW, if this forum is running on JBoss then it's a terrible JBoss advertisement...
http://developer.jboss.org uses Jive. Feel free to report a problem.
-
5. Re: WELD-000225 warning in Tomcat 7, but servlets are synchronous!
chrisjr May 11, 2015 4:00 AM (in response to mkouba)Do you use asynchronous processing capabilities in JAX-RS 2.0?
Not yet, no. But it's something I might want to use in the future. At the moment, all asynchronous work is done in ThreadPools created either by me or by the AWS SDK.
For @SessionScoped it shouldn't be a problem - bean instances are destroyed outside the servlet request lifecycle, during HttpSessionListener.sessionDestroyed() invocation. For @ConversationScoped this shouldn't be a problem either - conversation cleanup is performed for every request. Unfortunately, for @RequestScoped beans this is a problem and bean instances are not destroyed correctly.
Fortunately for me, all of my beans are either @Dependent, @Singleton or @ApplicationScoped. So hopefully these Bean Stores are all empty ...
-
6. Re: WELD-000225 warning in Tomcat 7, but servlets are synchronous!
mkouba May 11, 2015 4:17 AM (in response to chrisjr)At the moment, all asynchronous work is done in ThreadPools created either by me or by the AWS SDK.
What async work?
-
7. Re: WELD-000225 warning in Tomcat 7, but servlets are synchronous!
chrisjr May 11, 2015 5:42 AM (in response to mkouba)What async work?
Submitting work to AWS, and waiting for SQS response messages in a separate thread. And on receiving a message, we start the next phase of processing.
We've previously had class-loader-like issues with WELD injections running from "non-container" / "user" threads (although I'm not sure why - I've found nothing in the CDI spec to explain it), and so our strategy is typically to create all of the beans up front and then launch our threads. However, we do appear to have the following code running in a user thread:
@Any Instance<ProcessingMethod> lookup; ... Instance<ProcessingMethod> instance = lookup.select(new MethodNameQualifierLiteral(token)); ProcessingMethod method = instance.get();
The idea here is that we have a set of @ApplicationScoped ProcessingMethod beans, each with its own @MethodName qualifier. And when the SQS message arrives, we ask WELD to "look up" the correct processing method bean to peform the next processing step. But maybe the Instance.select() method is doing things with bean stores? (I have no idea what Instance.select() is doing "under the covers" - I just know that it's executing in a user thread rather than a Tomcat-started thread).
-
8. Re: WELD-000225 warning in Tomcat 7, but servlets are synchronous!
mkouba May 11, 2015 6:24 AM (in response to chrisjr)I don't know much about AWS but if I understand it correctly you're not using async servlet API but doing the same using your own Tomcat/AWS specific stuff? If so then there is exactly the same problem as with async servlet API and Tomcat:
ServletRequestListener.requestInitialized()
callback is called from a different thread than the correspondingServletRequestListener.requestDestroyed()
callback. Note that Weld currently doesn't inspect the leaked bean store - so it may be empty. Maybe we should add a debug log message and write down some info about the beans found in the store.With regard to non-container threads and CDI: within a user-controlled thread only application context (which is always active), singletons (which are not very well defined in CDI) and dependent pseudo-scope will work (see also Weld FAQ). All other built-in contexts must be activated/deactivated by the container. There are many parts of the spec which mention threads, e.g. 6.2. The Context interface:
At a particular point in the execution of the program a context object may be active with respect to the current thread.
or 6.3. Normal scopes and pseudo-scopes:
The context object for a normal scope type is a mapping from each contextual type with that scope to an instance of that contextual type. There may be no more than one mapped instance per contextual type per thread.
Instance.get()
does work with bean stores because it tries to obtain a contextual reference for a selected bean. -
9. Re: WELD-000225 warning in Tomcat 7, but servlets are synchronous!
chrisjr May 11, 2015 7:08 AM (in response to mkouba)but if I understand it correctly you're not using async servlet API but doing the same using your own Tomcat/AWS specific stuff?
Not quite. We don't use @RequestScoped beans at all, and allow the synchronous requests to end naturally. The asynchronous work is performed in the background by @ApplicationScoped and @Dependent beans.
With regard to non-container threads and CDI: within a user-controlled thread only application context (which is always active), singletons (which are not very well defined in CDI) and dependent pseudo-scope will work.
This is fine; we rarely use any other kind of bean anyway . I think our problems were more related to classes not being found when WELD tried to instantiate lazy proxies; it was very odd and happened with WELD 2.0.4.Final (I think). Getting WELD to inject everything before spawning new threads fixed the problem (i.e. "eager" vs "lazy" beans), and it's a practice we've stuck with ever since.
-
10. Re: WELD-000225 warning in Tomcat 7, but servlets are synchronous!
chrisjr May 12, 2015 4:18 AM (in response to mkouba)I tried replacing our Instance.select().get() code with a simple switch statement, but I'm still seeing WELD-000714 / WELD-000225 / WELD-000335 warnings. So it's not that either.
-
11. Re: WELD-000225 warning in Tomcat 7, but servlets are synchronous!
mkouba May 12, 2015 4:31 AM (in response to chrisjr)I have no idea. It would be great if you could prepare a simplified application so that we could reproduce the issue locally.
-
12. Re: WELD-000225 warning in Tomcat 7, but servlets are synchronous!
chrisjr May 12, 2015 8:25 AM (in response to mkouba)When it comes to reproducing this issue, it seems only to be happening in AWS because my Tomcat in AWS is constantly receiving unrelated HTTP requests. E.g. the application has a RESTeasy "health check" handler which AWS is polling regularly:
@ValidateOnExecution @ApplicationScoped public class HealthCheckBean implements HealthCheck { @Override public Response health() { return Response.ok().build(); } } @Path("/health") public interface HealthCheck { @GET @HEAD Response health(); }
I think that it is these other handlers that are triggering the WELD-000225 warnings. (My AWS Tomcat was also just scanned for CGI scripts by some Nice Little Internet Person - that resulted in a lot of WELD-000225 warnings too!)
-
13. Re: WELD-000225 warning in Tomcat 7, but servlets are synchronous!
mkouba May 12, 2015 10:03 AM (in response to chrisjr)I still don't see a reason why the health check should cause the warnings. Did you try to test the health check locally (gatling, jmeter)?
-
14. Re: WELD-000225 warning in Tomcat 7, but servlets are synchronous!
chrisjr May 12, 2015 3:08 PM (in response to mkouba)I'm not saying that every invocation of the health check triggers a WELD-000225 warning. I've simply compared the timestamps of the warnings with the timestamps in the localhost_access log and identified what the URLs were.