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 2018/09/02 03:15:51 UTC

[Bug 62670] New: driverManagerProtection in JreMemoryLeakPreventionListener results in java.sql.SQLException: No suitable driver found

https://bz.apache.org/bugzilla/show_bug.cgi?id=62670

            Bug ID: 62670
           Summary: driverManagerProtection in
                    JreMemoryLeakPreventionListener results in
                    java.sql.SQLException: No suitable driver found
           Product: Tomcat 8
           Version: 8.5.x-trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: srp.naren@gmail.com
  Target Milestone: ----

Created attachment 36128
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=36128&action=edit
index.jsp file - can be dropped in any example webapps

Tomcat shows "java.sql.SQLException: No suitable driver found for
jdbc:postgresql://localhost:5432/postgres ..." (applies to other drivers too)
when the driver class is not explicitly loaded using Class.forName("...")

The DriverManager
(https://docs.oracle.com/javase/8/docs/api/java/sql/DriverManager.html) spec
states that this is not required (The jdbc4+ drivers use service loaders to
register themselves)

This seems to be because of driverManagerProtection in
JreMemoryLeakPreventionListener. When this flag is set to 'false' in
conf/server.xml, the database connection works as expected. 

The bug was observed when postgresql-42.2.2.jar was placed in CATALINA_HOME/lib
or in CATALINA_HOME/webapps/examples/WEB-INF/lib/

-- 
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 62670] driverManagerProtection in JreMemoryLeakPreventionListener results in java.sql.SQLException: No suitable driver found

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

--- Comment #5 from Mark Thomas <ma...@apache.org> ---
Getting back to the original bug report...

The behaviour described is expected when a JDBC driver is packaged in
WEB-INF/lib. The behaviour (and explanation for it) is documented here:
http://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto.html

That default behaviour is not going to change.

The described behaviour when the driver is in CATALINA_HOME/lib is not
expected. That needs further investigation.

-- 
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 62670] driverManagerProtection in JreMemoryLeakPreventionListener results in java.sql.SQLException: No suitable driver found

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

--- Comment #4 from Mark Thomas <ma...@apache.org> ---
This is getting rather off-topic for this bug. I don't see anything in that
guidance that needs changing. If you have suggested edits, I suggest you take
them to the dev@ for the community to discuss them.

-- 
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 62670] driverManagerProtection in JreMemoryLeakPreventionListener results in java.sql.SQLException: No suitable driver found

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

--- Comment #1 from Michael Osipov <19...@gmx.net> ---
A JDBC driver should never be placed in WEB-INF/lib/. So in this case it would
be an invalid issue. The other one might be misuse.

-- 
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 62670] driverManagerProtection in JreMemoryLeakPreventionListener results in java.sql.SQLException: No suitable driver found

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

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

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

--- Comment #9 from Mark Thomas <ma...@apache.org> ---
Fixed in:
- trunk for 9.0.12 onwards
- 8.5.x for 8.5.34 onwards
- 7.0.x for 7.0.91 onwards

-- 
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 62670] driverManagerProtection in JreMemoryLeakPreventionListener results in java.sql.SQLException: No suitable driver found

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

--- Comment #2 from Mark Thomas <ma...@apache.org> ---
(In reply to Michael Osipov from comment #1)
> A JDBC driver should never be placed in WEB-INF/lib/.

Of course it can. Such use is perfectly valid.

-- 
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 62670] driverManagerProtection in JreMemoryLeakPreventionListener results in java.sql.SQLException: No suitable driver found

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

--- Comment #6 from Mark Thomas <ma...@apache.org> ---
It is a class loader issue. When the service loader executes it uses the
bootstrap class loader which does not include $CATALINA_HOME/lib

I'm not sure if this is something that has changed in the JRE or a long
standing Tomcat bug. Not that it matters much in this case as it won't affect
the fix.

The fix should be simple. If I don't get time to fix it today, I'll certainly
have time tomorrow.

-- 
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 62670] driverManagerProtection in JreMemoryLeakPreventionListener results in java.sql.SQLException: No suitable driver found

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

--- Comment #7 from Padmanarayanan <sr...@gmail.com> ---
(In reply to Mark Thomas from comment #5)
> Getting back to the original bug report...
> 
> The behaviour described is expected when a JDBC driver is packaged in
> WEB-INF/lib. The behaviour (and explanation for it) is documented here:
> http://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto.html
> 
> That default behaviour is not going to change.
> 
> The described behaviour when the driver is in CATALINA_HOME/lib is not
> expected. That needs further investigation.

Could you also clarify about the shared/endorsed lib?

-- 
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 62670] driverManagerProtection in JreMemoryLeakPreventionListener results in java.sql.SQLException: No suitable driver found

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

--- Comment #3 from Michael Osipov <19...@gmx.net> ---
(In reply to Mark Thomas from comment #2)
> (In reply to Michael Osipov from comment #1)
> > A JDBC driver should never be placed in WEB-INF/lib/.
> 
> Of course it can. Such use is perfectly valid.

Are you certain, isn't the driver pinned into memory by the DriverManager when
the webapp is undeployed? There are zillion of discussions about this in
Stackoverflow.

If so, this
(http://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto.html#DriverManager,_the_service_provider_mechanism_and_memory_leaks)
should be improved because this pops up once in a while on SO and other places.

-- 
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 62670] driverManagerProtection in JreMemoryLeakPreventionListener results in java.sql.SQLException: No suitable driver found

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

--- Comment #8 from Mark Thomas <ma...@apache.org> ---
Sure. I can include that in the doc updates.
The short version is:
- endorsed (where the JRE still supports it) is effectively the same as the
system class path
- using the shared loader (where it has been configured since it is not used by
default) needs to be handled the same was as the web application class loader.

-- 
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