Hi,

I have downloaded tomcat source but couldn't find this dbcp package under
"org.apache.tomcat".

I have figured out when it happens.

I have a class "ConnectionManager" which is called to get the connection
object.

It is singleton class and I call the below method to get the object
public static ConnectionManager getInstance() {

if (objConnectionManager == null)
objConnectionManager = new ConnectionManager();

return objConnectionManager;
}


Here is the method which is called to get the connection object and return
it

// This is original method to get DataSource.
public Connection getDataSource(String dnis) {

Connection connection = null;
if (!initialized)
createContext();
try {
.....
                      objDataSource = (DataSource)
envContext.lookup(dataSourceName);
try {
connection = objDataSource.getConnection(userName, password);
} catch (SQLException e) {
objLogger.error("[" + ucid + "]"
+ "SQLException in connection manager: "
+ e.getMessage());
}

} catch (NamingException e) {
objLogger.info("[" + ucid + "]"
+ "NamingException in connection manager: "
+ e.getMessage());
e.printStackTrace();
}
return connection;
}

This issue happens when this class is accessed through singleton object.
It doesn't happen when do one of the following:
1) make the method as synchronized.
or
2) remove singleton and initialize an object for every request for
ConnectionManager.

I could reproduce it by keeping two datasource and sending simultaneous
request to both the datasource using singleton ConnectionManager.

Please advice what could be the reason.
I have verified the SQL log when this incident happens it throws Login
failed for user "". Reason: "Password didn't match that for login provided".

Please advice whether singleton object can't be used when using multiple
datasources.

Thanks
Vinoth

On Thu, Feb 12, 2015 at 12:09 AM, Christopher Schultz <
ch...@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Vinoth,
>
> On 2/10/15 10:03 PM, Vinoth Raja wrote:
> > Thanks for the quick response.
> >
> > Please find the stack trace. This happens when there is more
> > requests. I could reproduce it by loading more concurrent request
> > All datasources called with same username/password. 4 datasources
> > are called at a time by 4 different application.
>
> This is a little confusing:
>
> > INFO: Stopping ProtocolHandler ["ajp-bio-8009"]
> > ionFilterChain.java:208) at
> >
> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
>
> I
> >
> think something has been cut-off, here.
>
> > at
> >
> org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
> >
> >
> at
> >
> org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
> >
> >
> at
> >
> org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
> >
> >
> at com.avaya.sce.runtime.SCEServlet.forward(SCEServlet.java:1356)
> > at
> > com.avaya.sce.runtime.BasicServlet.handleRequest(BasicServlet.java:116)
> >
> >
> at com.avaya.sce.runtime.AppServlet.processRequest(AppServlet.java:96)
> > at
> > com.avaya.sce.runtime.SCEServlet.requestHandler(SCEServlet.java:285)
> >
> >
> at com.avaya.sce.runtime.SCEServlet.doGet(SCEServlet.java:182)
> > at javax.servlet.http.HttpServlet.service(HttpServlet.java:620) at
> > javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at
> >
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
> >
> >
> at
> >
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
> >
> >
> at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
> > at
> >
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
> >
> >
> at
> >
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
> >
> >
> at
> >
> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
> >
> >
> at
> >
> org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
> >
> >
> at
> >
> org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
> >
> >
> at
> >
> org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
> >
> >
> at com.avaya.sce.runtime.SCEServlet.forward(SCEServlet.java:1356)
> > at com.avaya.sce.runtime.Data.handleRequest(Data.java:153) at
> > com.avaya.sce.runtime.AppServlet.processRequest(AppServlet.java:96)
> >
> >
> at com.avaya.sce.runtime.SCEServlet.requestHandler(SCEServlet.java:285)
> > at com.avaya.sce.runtime.SCEServlet.doGet(SCEServlet.java:182) at
> > javax.servlet.http.HttpServlet.service(HttpServlet.java:620) at
> > javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at
> >
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
> >
> >
> at
> >
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
> >
> >
> at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
> > at
> >
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
> >
> >
> at
> >
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
> >
> >
> at
> >
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
> >
> >
> at
> >
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
> >
> >
> at
> >
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
> >
> >
> at
> >
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
> >
> >
> at
> >
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
> >
> >
> at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
> > at
> >
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
> >
> >
> at
> >
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
> >
> >
> at
> >
> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
> >
> >
> at
> >
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
> >
> >
> at
> >
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
> >
> >
> at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
> > at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown
> > Source) at
> >
> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
> >
> >
> at java.lang.Thread.run(Unknown Source)
> > java.sql.SQLException: Given password did not match password used
> > to create the PooledConnection. at
> >
> org.apache.tomcat.dbcp.dbcp.datasources.InstanceKeyDataSource.getConnection(InstanceKeyDataSource.java:723)
> >
> >
> at
> >
> com.avaya.aps.sca.selfservice.dm.ConnectionManager.getDataSource(ConnectionManager.java:101)
> >
> >
> at
> >
> com.avaya.aps.sca.selfservice.InteractionFlowServiceDaoImpl.getTransitionMapDetail(InteractionFlowServiceDaoImpl.java:241)
>
> What
> >
> code is being called, here in DBCP? You are calling the
> getConnection method that accepts a username and password. Are you
> sure you are not changing the password?
>
> The code in that area looks like this:
>
>  if (!(null == password ? null == info.getPassword()
> 717     : password.equals(info.getPassword()))) { // Password on
> PooledConnectionAndInfo does not match
> 718     try { // See if password has changed by attempting connection
> 719     testCPDS(username, password);
> 720     } catch (SQLException ex) {
> 721     // Password has not changed, so refuse client, but return
> connection to the pool
> 722     closeDueToException(info);
> 723     throw new SQLException("Given password did not match password used"
> 724     + " to create the PooledConnection.");
> 725     } catch (javax.naming.NamingException ne) {
> 726     throw (SQLException) new SQLException(
> 727     "NamingException encountered connecting to
> database").initCause(ne);
> 728     }
> 729
>
> It's possible that a SQLException is occurring that does not represent
> a password problem, but it's being interpreted as such.
>
> I checked, and DBCP 2.0 does the same thing: it swallows the
> SQLException so you'll never know what really happened.
>
> It's possible that, in testCPDS, you are running across this:
>
> 819     if (ds instanceof ConnectionPoolDataSource) {
> 820     cpds = (ConnectionPoolDataSource) ds;
> 821     } else {
> 822     throw new SQLException("Illegal configuration: "
> 823     + "DataSource " + dataSourceName
> 824     + " (" + ds.getClass().getName() + ")"
> 825     + " doesn't implement javax.sql.ConnectionPoolDataSource");
> 826     }
>
> Can you put a breakpoint in testCBDS and see what happens to these
> connections?
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1
> Comment: GPGTools - http://gpgtools.org
>
> iQIcBAEBCAAGBQJU237WAAoJEBzwKT+lPKRYkLwP/AkNISPIG6FDjkzZN2Pp7R/y
> zcbyOQLVjiVXvK/hsGdv6Brf/KPTMBaljE7NQ7y/l26BSz5FM2jPkh7iqa91TMB7
> SjZ0vWXDqDGp1VpNz8EAP63hajsbVzHS4RuFCGHQFDpAFUfPqx/eRkEQm+fMMHj0
> 8wmEicD4XvrCNvNITSkUW02bkG4Ii14ggJWz4Fix7e6aVq2FivEsDXUao5ma27IX
> QuYxseBFKHqQ8hrTbB74wvB4IIFpveEZmS2vNIL4rKVbXclbmseuwtj8nTyEqNSa
> 1rzcYwhg1jndUbCcZS7POQq+vGcs6mJNplyleR7aSotR1G7ApZ3hMCN68TIuWYzq
> Vg7/5xUg1oMaGxuxiXPUMwKLT7KfA1ATTIhk8rSPATMEEGc8l8a+azHtLuf9ebqv
> fXTU0bdYWL+D0tkDi7Pg9hA47Jm2wK3j0yMgsyv31wIRLLYkHwVwoo/ZiYcWOH/y
> 3H6fXuGB1obX75KR/dAdUL2BrVb7yxBBrILf3sjRIk2gtNk2KikE06gtCU178oct
> 5Q7XMmhbxmiRYlo+M1h8gWKcGwE40dH9jrqD3I8mvCipIXSZTbI3Tn1m0xOdn8RT
> DhDpEFc7L1BoCjjnElC5W9ukFFtpsRgDVN12AsCAoPldbbYH4IDvuQPPGgdL1GnQ
> gphexbRn5miaGnJbpMa1
> =AyHt
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

Reply via email to