Bug 59077 - DataSourceFactory creates a neutered data source
Summary: DataSourceFactory creates a neutered data source
Status: NEW
Alias: None
Product: Tomcat Modules
Classification: Unclassified
Component: jdbc-pool (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-26 18:52 UTC by Kenneth Gendron
Modified: 2016-03-07 01:44 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kenneth Gendron 2016-02-26 18:52:52 UTC
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);
        }
    }
Comment 1 Mark Thomas 2016-03-02 13:06:24 UTC
Correct product.
Comment 2 Kenneth Gendron 2016-03-07 00:34:19 UTC
Sorry to ask, but does this mean its by design, or should be fixed?
Comment 3 Christopher Schultz 2016-03-07 01:44:57 UTC
(In reply to Kenneth Gendron from comment #2)
> Sorry to ask, but does this mean its by design, or should be fixed?

I believe Mark changed the "product" field in the bug report and made a comment to that effect. It's not a comment on the validity of the bug report itself.