From bc29864be67d756f82a0666ac364388805673685 Mon Sep 17 00:00:00 2001 From: DigitalSonic Date: Sat, 12 Oct 2019 16:16:42 +0800 Subject: [PATCH] close DataSource if creation failed close the DataSource if creation failed, otherwise the create-thread will try to create Connection and log ERROR in an endless loop --- .../com/alibaba/druid/pool/ha/DataSourceCreator.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/alibaba/druid/pool/ha/DataSourceCreator.java b/src/main/java/com/alibaba/druid/pool/ha/DataSourceCreator.java index e8109d1120..aad52ed234 100644 --- a/src/main/java/com/alibaba/druid/pool/ha/DataSourceCreator.java +++ b/src/main/java/com/alibaba/druid/pool/ha/DataSourceCreator.java @@ -66,11 +66,19 @@ public class DataSourceCreator { String username = properties.getProperty(n + ".username"); String password = properties.getProperty(n + ".password"); LOG.info("Creating " + n + " with url[" + url + "] and username[" + username + "]."); + DruidDataSource dataSource = null; try { - DruidDataSource dataSource = create(n, url, username, password, haDataSource); + dataSource = create(n, url, username, password, haDataSource); map.put(n, dataSource); } catch(Exception e) { LOG.error("Can NOT create DruidDataSource for " + n, e); + if (dataSource != null) { + try { + dataSource.close(); + } catch (Exception ex) { + LOG.error("Exception occurred while closing the FAILURE DataSource.", ex); + } + } } } LOG.info(map.size() + " DruidDataSource(s) created. "); @@ -172,7 +180,7 @@ public class DataSourceCreator { try { is.close(); } catch (Exception e) { - // ignore + LOG.debug("Can not close Inputstream.", e); } } }