You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2012/05/26 23:36:56 UTC

[Bug 53301] New: Servlet init method called twice with embedded Tomcat

https://issues.apache.org/bugzilla/show_bug.cgi?id=53301

          Priority: P2
            Bug ID: 53301
          Assignee: dev@tomcat.apache.org
           Summary: Servlet init method called twice with embedded Tomcat
          Severity: major
    Classification: Unclassified
          Reporter: jeffmaury@jeffmaury.com
          Hardware: PC
            Status: NEW
           Version: 7.0.27
         Component: Servlet & JSP API
           Product: Tomcat 7

When using embedded Tomcat, the servlet init method is called twice by the
container. This has been seen with an Apache DirectMemory unit test. I have
checked with a normal Tomcat launched by the Tomcat Maven plugin (mvn
tomcat7:run) and in this case, the init method is correctly called once.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 53301] Servlet init method called twice with embedded Tomcat

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53301

--- Comment #5 from Jeff MAURY <je...@jeffmaury.com> ---
Created attachment 28844
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=28844&action=edit
Sample Maven project with a test

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 53301] Servlet init method called twice with embedded Tomcat

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53301

--- Comment #3 from Konstantin Kolinko <kn...@gmail.com> ---
> Don't understand why you claim it is a user error

It is your responsibility to provide enough details to prove and reproduce the
issue. Your report is lacking and there are several statements in it that
appear to be based on false assumptions.

You should ask for help on the users list to better diagnose your problem.
Bugzilla is not a support forum.

FYI:
1. tomcat7:run uses embedded Tomcat 
2. init() can be called as many times as many instances of a Servlet are there

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 53301] Servlet init method called twice with embedded Tomcat

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53301

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #8 from Mark Thomas <ma...@apache.org> ---
Thanks for the analysis Konstantin - that made the fix very simple.

Fixed in trunk and 7.0.x and will be included in 7.0.28 onwards. I also
included a test case for this.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 53301] Servlet init method called twice with embedded Tomcat

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53301

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID
                 OS|                            |All

--- Comment #1 from Mark Thomas <ma...@apache.org> ---
This is user error. Use the users mailing list to debug.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 53301] Servlet init method called twice with embedded Tomcat

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53301

--- Comment #2 from Jeff MAURY <je...@jeffmaury.com> ---
Don't understand why you claim it is a user error

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 53301] Servlet init method called twice with embedded Tomcat

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53301

--- Comment #7 from Konstantin Kolinko <kn...@gmail.com> ---
Created attachment 28845
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=28845&action=edit
SampleServlet.java

SampleServlet.java update.
Added stackstace printing in init(). Overwrote destroy().

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 53301] Servlet init method called twice with embedded Tomcat

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53301

Konstantin Kolinko <kn...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---
           Severity|major                       |normal

--- Comment #6 from Konstantin Kolinko <kn...@gmail.com> ---
Ok. Reproducible.

I modified your SampleServlet to print stacktrace when init() is called, like
this:
[[[
    @Override
    public void init( ServletConfig config )
        throws ServletException
    {
        log.info( "Init called, config="+config, new Throwable() );
        super.init( config );
...
]]]

I'll attach full source later. There are two calls to init() in a row and stack
traces are the following:
[[[
00:58:32.187 [main] INFO  init - Tomcat started on port:4396
00:58:32.609 [http-bio-auto-1-exec-1] INFO  init - Init called,
config=org.apache.catalina.core.StandardWrapperFacade@15e2075
java.lang.Throwable: null
 at org.apache.tomcat.tomcat53301.SampleServlet.init(SampleServlet.java:43)
[classes/:na]
 at
org.apache.catalina.startup.Tomcat$ExistingStandardWrapper.loadServlet(Tomcat.java:854)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
[na:1.6.0_32]
 at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
[na:1.6.0_32]
 at java.lang.Thread.run(Thread.java:662) [na:1.6.0_32]
00:58:32.625 [http-bio-auto-1-exec-1] INFO  init - Init called,
config=org.apache.catalina.core.StandardWrapperFacade@15e2075
java.lang.Throwable: null
 at org.apache.tomcat.tomcat53301.SampleServlet.init(SampleServlet.java:43)
[classes/:na]
 at
org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:877)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
[na:1.6.0_32]
 at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
[na:1.6.0_32]
 at java.lang.Thread.run(Thread.java:662) [na:1.6.0_32]
]]]

Essentially it is the same single call to
org.apache.catalina.core.StandardWrapper.allocate()
and it calls init() twice with the following stack traces
a)
[[[
 at org.apache.tomcat.tomcat53301.SampleServlet.init(SampleServlet.java:43)
[classes/:na]
 at
org.apache.catalina.startup.Tomcat$ExistingStandardWrapper.loadServlet(Tomcat.java:854)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857)
[tomcat-embed-core-7.0.27.jar:7.0.27]
]]]
b)
[[[
 at org.apache.tomcat.tomcat53301.SampleServlet.init(SampleServlet.java:43)
[classes/:na]
 at
org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
[tomcat-embed-core-7.0.27.jar:7.0.27]
 at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:877)
[tomcat-embed-core-7.0.27.jar:7.0.27]
]]]

The second call happens because StandardWrapper#instanceInitialized flag is
still false, but init() has already been called by
Tomcat$ExistingStandardWrapper.loadServlet().

So either Tomcat$ExistingStandardWrapper should not call init(), or it should
update the flag when doing so.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 53301] Servlet init method called twice with embedded Tomcat

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53301

--- Comment #4 from Jeff MAURY <je...@jeffmaury.com> ---
Sorry, but the intent was not to get support but rather to signal the Tomcat
community of the problem.
I agree I should have given more materials about the problem: so you should
find now a sample Maven project that demonstrate the problem. Just run 'mvn
test' and you should get the error.
This has been tested against 7.0.27, 7.0.26 and 7.0.25 (using the tomcatVersion
property)

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 53301] Servlet init method called twice with embedded Tomcat

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53301

wan_jm@126.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wan_jm@126.com

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org