vipx / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Incorrect error report when using Jersey and Guice and forget to annotate a resource constructor with @Inject #698

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
If I attempt to add a resource to my GuiceServletConfig and then forgot to 
annotate the constructor with @Inject, Tomcat will throw a error reporting that 
there is a hanging thread or a potential memory leak.

SEVERE: Error listenerStart
SEVERE: Context [/api] startup failed due to previous errors
SEVERE: The web application [/api] appears to have started a thread named 
[com.google.inject.internal.util.$Finalizer] but has failed to stop it. This is 
very likely to create a memory leak.
SEVERE: The web application [/api] created a ThreadLocal with key of type 
[com.google.inject.internal.InjectorImpl$1] (value 
[com.google.inject.internal.InjectorImpl$1@495a2dc4]) and a value of type 
[java.lang.Object[]] (value [[Ljava.lang.Object;@3f72c47b]) but failed to 
remove it when the web application was stopped. Threads are going to be renewed 
over time to try and avoid a probable memory leak.

After annotated the constructor this goes away. This isn't a huge issue, but 
the error reporting is bad and if I hadn't noticed that I forgot to annotate 
the constructor, this could have been a bang my head against the wall type of 
day/days.

Original issue reported on code.google.com by herring...@gmail.com on 6 Apr 2012 at 4:46

GoogleCodeExporter commented 9 years ago
These warning messages are actually unrelated to whether the constructor had 
@Inject or not - the early exit of the context just meant they were more likely 
to appear. See issue 288 and issue 707 for more details about these warnings 
and their current status.

Original comment by mccu...@gmail.com on 7 Aug 2012 at 7:00

GoogleCodeExporter commented 9 years ago
I always get the message and can't not start my webapps. So i think it's not 
just a warning message but a fatal error. Please advise. Thanks.

Original comment by 234aini on 2 Sep 2012 at 10:26

GoogleCodeExporter commented 9 years ago
None of the messages above relate to startup, only to shutdown. This is 
indicated by the line "Context [/api] startup failed due to previous errors", 
meaning that an error before that line caused the webapp to not start.

If you search your log files above the line "Context [/api] startup failed due 
to previous errors" (or alternatively search down from the first line where the 
web container says it is deploying the webapp) then you should find the cause 
of the startup failure.

Original comment by mccu...@gmail.com on 2 Sep 2012 at 10:32

GoogleCodeExporter commented 9 years ago
I got this warning message in Fatal level when deploy my webapp to tomcat.
 I have tried to kill  the tomcat process and then start tomcat again.

In my scenario,  it only appear at context listener is loaded.

Actually, I have resolved this problem in my local and I found that it's
caused by that there are some dependence errors. I mean some bindings are
wrong. But what confused me is that why i got this as the error message but
I can not get the 'REAL' exception stack trace.

Any advise?

Original comment by 234aini on 2 Sep 2012 at 12:00

GoogleCodeExporter commented 9 years ago
Regarding binding errors: depending on the actual binding problem you should 
either get an exception when you first create the injector or when you try to 
get an instance from the injector. Either way an exception will be thrown 
describing the problem. Now depending on your application code this exception 
may be caught and logged, caught and ignored, or not caught (in which case it 
will bubble up to the web container, which may itself log or swallow the 
exception). Either way there's not much that Guice can do - it correctly threw 
the exception back to the application for it to handle. It doesn't 
automatically log these exceptions itself, but leaves it to the application 
since the problem might be expected/recoverable. You might want to protect 
calls to construct the injector / get instances with try-catch blocks and your 
own logging rather than leave it up to the container's uncaught-exception 
handler. (Guava's Throwables utility class can be helpful here.)

BTW, for tomcat uncaught exceptions may appear in the localhost log instead of 
the usual catalina log where most console messages go: 
http://stackoverflow.com/questions/4029864/uncaught-exceptions-in-tomcat-print-t
o-localhost-date-log-instead-of-catalina

Regarding the tomcat messages: see 
http://wiki.apache.org/tomcat/MemoryLeakProtection - Tomcat logs these as 
'severe' (presumably to attract attention, which seems to work) but they are 
not actually fatal and the detection is only run at shutdown of a webapp and 
not during startup. In fact for the threadlocals case they often would get 
cleaned up (see discussion about the JDK's threadlocal implementation / 
expungeStaleEntries in the above link) but tomcat logs them as something to be 
investigated (see also the ongoing discussion in issue 288).

Original comment by mccu...@gmail.com on 2 Sep 2012 at 12:46

GoogleCodeExporter commented 9 years ago

Original comment by mccu...@gmail.com on 2 Sep 2012 at 12:48

GoogleCodeExporter commented 9 years ago
Thanks a bunch.

You are exactly right. I found the error message
in localhost.2012-09-02.log.

And also, as you suggestion. I try/catch the exception by my self when
create Guice injector and I finally got the real exception stack trace.
Lots of help. Thanks.

Have to say that it's not caused by Guice and maybe caused by Tomcat or
Struts2 Gucie plugin I am used.

Original comment by 234aini on 2 Sep 2012 at 1:11