<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>For English only</strong>, other languages will not accept.</p>
<p dir="auto">Before report a bug, make sure you have:</p>
<ul dir="auto">
<li>Searched open and closed <a href="https://github.com/apache/incubator-shardingsphere-example/issues">GitHub issues</a>.</li>
<li>Read documentation: <a href="https://shardingsphere.apache.org/document/current/en/overview" rel="nofollow">ShardingSphere Doc</a>.</li>
</ul>
<p dir="auto">Please pay attention on issues you submitted, because we maybe need more details.<br>
If no response <strong>more than 7 days</strong> and we cannot reproduce it on current information, we will <strong>close it</strong>.</p>
<p dir="auto">Please answer these questions before submitting your issue. Thanks!</p>
<h3 dir="auto">Which version of ShardingSphere did you use?</h3>
<p dir="auto">4.0.0-RC1</p>
<h3 dir="auto">Which project did you use? Sharding-JDBC or Sharding-Proxy?</h3>
<p dir="auto">Sharding-JDBC</p>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/35563513/60314879-d50c2d80-9996-11e9-933a-ff225661b11d.png"><img src="https://user-images.githubusercontent.com/35563513/60314879-d50c2d80-9996-11e9-933a-ff225661b11d.png" alt="image" style="max-width: 100%;"></a><br>
insert success</p>
<h3 dir="auto">Actual behavior</h3>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/35563513/60314841-b0b05100-9996-11e9-95ac-5d389e0a8e5e.png"><img src="https://user-images.githubusercontent.com/35563513/60314841-b0b05100-9996-11e9-95ac-5d389e0a8e5e.png" alt="image" style="max-width: 100%;"></a><br>
insert error</p>
<h3 dir="auto">Reason analyze (If you can)</h3>
<p dir="auto">unknown</p>
<h3 dir="auto">Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.</h3>
<p dir="auto">insert primary key null will report exception</p>
<h3 dir="auto">Example codes for reproduce this issue (such as a github link).</h3>
<p dir="auto"><a href="https://github.com/M-make/jnote">https://github.com/M-make/jnote</a>   -&gt; com.jdbc.sharding.TestSharding#testSharding</p>
<h2 dir="auto">Bug Report</h2>
<h3 dir="auto">Which version of ShardingSphere did you use?</h3>
<p dir="auto">5.1.1 Release</p>
<h3 dir="auto">Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?</h3>
<p dir="auto">ShardingSphere-Proxy</p>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">All the add-resources dist-sql will success if all the jdbc properties are correct.</p>
<h3 dir="auto">Actual behavior</h3>
<p dir="auto">Add-resource dist-sql may failed after serveral success.</p>
<h3 dir="auto">Reason analyze (If you can)</h3>
<p dir="auto">concurrent issue</p>
<ol dir="auto">
<li>datasource graceful close is triggered async in validate method</li>
<li>getting jdbc connection from datasource is required to fetch db meta in addresource method</li>
</ol>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/41630875/170035675-19c815ac-d0d0-40f2-952b-c3c236f7276c.png"><img width="1060" alt="image" src="https://user-images.githubusercontent.com/41630875/170035675-19c815ac-d0d0-40f2-952b-c3c236f7276c.png" style="max-width: 100%;"></a></p>
<h3 dir="auto">Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.</h3>
<p dir="auto">executing add-resource distsql continuously  may leads to this problem. In my case, client would receive exception after 2~3 successful add-resource distsql<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/41630875/170036808-0b2484f9-dde3-4c0b-bc55-9b1690c70e54.png"><img src="https://user-images.githubusercontent.com/41630875/170036808-0b2484f9-dde3-4c0b-bc55-9b1690c70e54.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">and stacktrace in shardingproxy server :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[ERROR] 2022-05-24 20:01:09.465 [ShardingSphere-Command-5] o.a.s.p.b.t.d.r.r.AddResourceBackendHandler - Add resource failed
java.lang.IllegalArgumentException: HikariDataSource HikariDataSource (HikariPool-163) has been closed.
	at org.apache.shardingsphere.infra.database.type.DatabaseTypeRecognizer.getDatabaseType(DatabaseTypeRecognizer.java:55)
	at org.apache.shardingsphere.infra.database.type.DatabaseTypeRecognizer.getDatabaseType(DatabaseTypeRecognizer.java:44)
	at org.apache.shardingsphere.infra.metadata.schema.loader.SchemaLoader.load(SchemaLoader.java:52)
	at org.apache.shardingsphere.infra.metadata.database.loader.DatabaseLoader.load(DatabaseLoader.java:53)
	at org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder.addSchema(MetaDataContextsBuilder.java:84)
	at org.apache.shardingsphere.mode.manager.ContextManager.buildChangedMetaDataContextWithAddedDataSource(ContextManager.java:478)
	at org.apache.shardingsphere.mode.manager.ContextManager.refreshMetaDataContext(ContextManager.java:451)
	at org.apache.shardingsphere.mode.manager.ContextManager.addResource(ContextManager.java:232)
	at org.apache.shardingsphere.proxy.backend.text.distsql.rdl.resource.AddResourceBackendHandler.execute(AddResourceBackendHandler.java:64)
	at org.apache.shardingsphere.proxy.backend.text.distsql.rdl.resource.AddResourceBackendHandler.execute(AddResourceBackendHandler.java:45)
	at org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler.execute(SchemaRequiredBackendHandler.java:51)
	at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:97)
	at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:100)
	at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:72)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: HikariDataSource HikariDataSource (HikariPool-163) has been closed.
	at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:96)
	at org.apache.shardingsphere.infra.database.type.DatabaseTypeRecognizer.getDatabaseType(DatabaseTypeRecognizer.java:52)
	... 16 common frames omitted"><pre class="notranslate"><code class="notranslate">[ERROR] 2022-05-24 20:01:09.465 [ShardingSphere-Command-5] o.a.s.p.b.t.d.r.r.AddResourceBackendHandler - Add resource failed
java.lang.IllegalArgumentException: HikariDataSource HikariDataSource (HikariPool-163) has been closed.
	at org.apache.shardingsphere.infra.database.type.DatabaseTypeRecognizer.getDatabaseType(DatabaseTypeRecognizer.java:55)
	at org.apache.shardingsphere.infra.database.type.DatabaseTypeRecognizer.getDatabaseType(DatabaseTypeRecognizer.java:44)
	at org.apache.shardingsphere.infra.metadata.schema.loader.SchemaLoader.load(SchemaLoader.java:52)
	at org.apache.shardingsphere.infra.metadata.database.loader.DatabaseLoader.load(DatabaseLoader.java:53)
	at org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder.addSchema(MetaDataContextsBuilder.java:84)
	at org.apache.shardingsphere.mode.manager.ContextManager.buildChangedMetaDataContextWithAddedDataSource(ContextManager.java:478)
	at org.apache.shardingsphere.mode.manager.ContextManager.refreshMetaDataContext(ContextManager.java:451)
	at org.apache.shardingsphere.mode.manager.ContextManager.addResource(ContextManager.java:232)
	at org.apache.shardingsphere.proxy.backend.text.distsql.rdl.resource.AddResourceBackendHandler.execute(AddResourceBackendHandler.java:64)
	at org.apache.shardingsphere.proxy.backend.text.distsql.rdl.resource.AddResourceBackendHandler.execute(AddResourceBackendHandler.java:45)
	at org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler.execute(SchemaRequiredBackendHandler.java:51)
	at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:97)
	at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:100)
	at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:72)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: HikariDataSource HikariDataSource (HikariPool-163) has been closed.
	at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:96)
	at org.apache.shardingsphere.infra.database.type.DatabaseTypeRecognizer.getDatabaseType(DatabaseTypeRecognizer.java:52)
	... 16 common frames omitted
</code></pre></div>
<h3 dir="auto">Example codes for reproduce this issue (such as a github link).</h3>
<p dir="auto">not necessary</p>