https://bz.apache.org/bugzilla/show_bug.cgi?id=59077
Bug ID: 59077 Summary: DataSourceFactory creates a neutered data source Product: Tomcat 8 Version: 8.0.30 Hardware: PC Status: NEW Severity: normal Priority: P2 Component: Catalina Assignee: dev@tomcat.apache.org Reporter: kenneth.gend...@gmail.com Suppose you have a datasource, "jdbc/ds" below, that for whatever reason the backing database is down and cannot be connected to. When Tomcat starts up it attempts to create the pooled datasource "jdbc/dspool"; however, due to the pseudo-random nature of how Tomcat creates resources the "jdbc/ds" datasource is not yet created. This does not pose a problem to the DataSourceFactory class since the performJNDILookup method does not throw an exception, but fails with only a log message. Tomcat does not retry to create the pooled datasource, and proceeds on, failing later on for "URL cannot be found", or some such error. Below is the server.xml configuration portion. <Resource name="jdbc/automationora" auth="Container" type="javax.sql.DataSource" username="automation" password="automation" factory="automation.sql.oracle.OracleDataSourceFactory" url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE)))" connectionProperties="oracle.jdbc.ReadTimeout=60000;"/> <Resource name="jdbc/automation" auth="Container" type="javax.sql.DataSource" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" dataSourceJNDI="automationora" maxActive="5" maxIdle="5" minIdle="5" maxWait="-1" initialSize="0" testOnBorrow="true" validationQuery="select 1 from dual"/> If, however, the performJNDILookup were modified to allow an Exception, namely a NamingException to be thrown, then it could be modified slightly to allow Tomcat to retry. Below, when the method fails to find the data source in the initial context, it could throw the resulting NamingException. Tomcat would then continue with the other resources, creating them, then come back and recreate the pooled datasource. public void performJNDILookup(Context context, PoolConfiguration poolProperties) throws NamingException { Object jndiDS = null; try { if (context!=null) { jndiDS = context.lookup(poolProperties.getDataSourceJNDI()); } else { log.warn("dataSourceJNDI property is configued, but local JNDI context is null."); } } catch (NamingException e) { log.debug("The name \""+poolProperties.getDataSourceJNDI()+"\" can not be found in the local context."); } if (jndiDS==null) { try { context = new InitialContext(); jndiDS = context.lookup(poolProperties.getDataSourceJNDI()); } catch (NamingException e) { log.warn("The name \""+poolProperties.getDataSourceJNDI()+"\" can not be found in the InitialContext."); throw e; } } if (jndiDS!=null) { poolProperties.setDataSource(jndiDS); } } -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org