You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "PDGGK (via GitHub)" <gi...@apache.org> on 2026/08/26 14:11:39 UTC
[PR] Close the connection when CatalogSwitchableDataSource fails to switch catalog [shardingsphere]
PDGGK opened a new pull request, #39609:
URL: https://github.com/apache/shardingsphere/pull/39609
Changes proposed in this pull request:
- Close the connection in `CatalogSwitchableDataSource#getConnection` when switching the catalog fails.
The connection is handed out by the pool before the catalog is applied:
```java
Connection result = dataSource.getConnection();
if (null != catalog && !catalog.equals(result.getCatalog())) {
result.setCatalog(catalog);
}
return result;
```
If `getCatalog` or `setCatalog` throws, the method exits with the connection already checked out of the pool and no reference to it anywhere. It is never closed and never returned. A catalog that does not exist, or a user without rights to it, makes `setCatalog` throw on every call, so each attempt takes one more connection out of the pool until the pool is empty and the failure changes from "unknown database" to a checkout timeout, which points nowhere near the actual cause.
`QuietlyCloser` is used rather than a `catch`, so the original failure is what the caller sees. A failure to close cannot replace it.
### Tests
Two in `CatalogSwitchableDataSourceTest`:
- `assertGetConnectionClosesTheConnectionWhenSwitchingCatalogFails` — `setCatalog` throws; the connection is closed and the original `SQLException` still comes out.
- `assertGetConnectionKeepsTheOriginalFailureWhenClosingAlsoFails` — closing throws too; the caller still gets the `setCatalog` failure rather than the close failure.
Both fail on `master` with `Wanted but not invoked: connection.close()`.
`mvn test -pl infra/data-source-pool/core` — 15 tests in that class, all passing.
---
Before committing this PR, I'm sure that I have checked the following options:
- [x] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
- [x] I have self-reviewed the commit code.
- [ ] I have (or in comment I request) added corresponding labels for the pull request.
- [x] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
- [ ] I have made corresponding changes to the documentation.
- [x] I have added corresponding unit tests for my changes.
- [ ] I have updated the Release Notes of the current development version. For more details, see [Update Release Note](https://shardingsphere.apache.org/community/en/involved/contribute/contributor/)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Close the connection when CatalogSwitchableDataSource fails to switch catalog [shardingsphere]
Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu merged PR #39609:
URL: https://github.com/apache/shardingsphere/pull/39609
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org