You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@grails.apache.org by "codeconsole (via GitHub)" <gi...@apache.org> on 2026/06/17 22:51:01 UTC
[PR] Do not close an externally-supplied MongoClient in GORM for MongoDB [grails-core]
codeconsole opened a new pull request, #15743:
URL: https://github.com/apache/grails-core/pull/15743
## What
GORM's connection-source shutdown closes any `Closeable` source, and `com.mongodb.client.MongoClient` is `Closeable`, so a client handed to GORM — a Spring-managed bean, or one passed to `new MongoDatastore(mongoClient, ...)` — was closed when the datastore shut down. That double-closes a client whose lifecycle is owned elsewhere.
This makes GORM **not close a `MongoClient` it did not create**:
- `DefaultConnectionSource` gains a non-closeable mode (new 4-arg constructor + `isCloseable()`); the existing constructor is unchanged, so there is no behavior change for current callers.
- `MongoDatastore.createDefaultConnectionSources` wraps an externally-supplied client as non-closeable.
- `MongoDbGormAutoConfiguration` implements `DisposableBean` and closes only the client it created itself; a client supplied as a bean is left for the application context to close.
GORM still closes clients it creates from `grails.mongodb.*` configuration.
## Why
- Removes a redundant double-close in the common Spring Boot setup (Spring already owns and closes the `MongoClient` bean).
- Establishes "whoever creates the client owns closing it" — the safe basis for sharing one `MongoClient` across GORM and other consumers.
## Behavior change
The only externally-visible change: callers that relied on `MongoDatastore.close()` to also close a client they passed in must now close it themselves. Documented in the upgrade notes.
## Tests
- `DefaultConnectionSourceSpec` — closes by default; no-op when non-closeable; closes an `AutoCloseable` when closeable.
- `MongoDatastoreExternalClientSpec` — a supplied client is not closed on datastore shutdown.
- `MongoDbGormAutoConfigurationCloseSpec` — the auto-config closes only an internally-created client.
Targets `8.0.x`.
--
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@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not close an externally-supplied MongoClient in GORM for MongoDB [grails-core]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #15743:
URL: https://github.com/apache/grails-core/pull/15743#issuecomment-4774226552
## [Codecov](https://app.codecov.io/gh/apache/grails-core/pull/15743?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 0.0000%. Comparing base ([`098660a`](https://app.codecov.io/gh/apache/grails-core/commit/098660ad3ceea412bd8b25eb1bb19ebf6aecd441?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`d95eb44`](https://app.codecov.io/gh/apache/grails-core/commit/d95eb4418714bf912ce3003ce4ac98ce5854be47?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 203 commits behind head on 8.0.x.
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/grails-core/pull/15743?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## 8.0.x #15743 +/- ##
=================================================
- Coverage 48.3729% 0 -48.3729%
=================================================
Files 1870 0 -1870
Lines 85457 0 -85457
Branches 14900 0 -14900
=================================================
- Hits 41338 0 -41338
+ Misses 37784 0 -37784
+ Partials 6335 0 -6335
```
[see 1870 files with indirect coverage changes](https://app.codecov.io/gh/apache/grails-core/pull/15743/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not close an externally-supplied MongoClient in GORM for MongoDB [grails-core]
Posted by "borinquenkid (via GitHub)" <gi...@apache.org>.
borinquenkid commented on PR #15743:
URL: https://github.com/apache/grails-core/pull/15743#issuecomment-4759258258
I'm sure this is not a totally rational fear, but I would point to https://github.com/apache/grails-core/pull/15678 since there was reworking of datastore creation
--
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@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not close an externally-supplied MongoClient in GORM for MongoDB [grails-core]
Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on PR #15743:
URL: https://github.com/apache/grails-core/pull/15743#issuecomment-4738066097
Why are you using gorm's mongo and spring's mongo?
--
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@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not close an externally-supplied MongoClient in GORM for MongoDB [grails-core]
Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on PR #15743:
URL: https://github.com/apache/grails-core/pull/15743#issuecomment-4759010396
This PR doesn't introduce any GORM↔Spring Mongo mixing — `MongoDbGormAutoConfiguration` has reused Spring Boot's auto-configured `MongoClient` (from `MongoAutoConfiguration`/`MongoProperties`) since 1.0, to avoid opening a second connection in a Boot app. The only change here is lifecycle: GORM no longer closes a `MongoClient` it didn't create (e.g. the Spring-managed bean), and the auto-config closes only the client it created itself. The Spring-mongo references in the diff are pre-existing context around the new `destroy()` method. (Note this is Spring Boot's Mongo auto-config, not Spring Data MongoDB.)
--
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@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not close an externally-supplied MongoClient in GORM for MongoDB [grails-core]
Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #15743:
URL: https://github.com/apache/grails-core/pull/15743#issuecomment-4759766437
## ✅ All tests passed ✅
🏷️ Commit: d95eb4418714bf912ce3003ce4ac98ce5854be47
▶️ Tests: 30243 executed
⚪️ Checks: 44/44 completed
---
_Learn more about TestLens at [testlens.app](https://testlens.app)._
--
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@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not close an externally-supplied MongoClient in GORM for MongoDB [grails-core]
Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on PR #15743:
URL: https://github.com/apache/grails-core/pull/15743#issuecomment-4783661054
Done — dropped the `test ` prefix, switched to single-quoted strings, and used `def` for the inferrable locals across all three specs.
--
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@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not close an externally-supplied MongoClient in GORM for MongoDB [grails-core]
Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #15743:
URL: https://github.com/apache/grails-core/pull/15743#issuecomment-4736638680
## ✅ All tests passed ✅
🏷️ Commit: 735529e5ce7cdc20eea743e1ea22db82d3bad75f
▶️ Tests: 24421 executed
⚪️ Checks: 44/44 completed
---
_Learn more about TestLens at [testlens.app](https://testlens.app)._
--
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@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not close an externally-supplied MongoClient in GORM for MongoDB [grails-core]
Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on code in PR #15743:
URL: https://github.com/apache/grails-core/pull/15743#discussion_r3463828271
##########
grails-data-mongodb/boot-plugin/src/test/groovy/org/grails/datastore/gorm/mongodb/boot/autoconfigure/MongoDbGormAutoConfigurationCloseSpec.groovy:
##########
Review Comment:
fixed
--
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@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not close an externally-supplied MongoClient in GORM for MongoDB [grails-core]
Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #15743:
URL: https://github.com/apache/grails-core/pull/15743#issuecomment-4784004536
## ✅ All tests passed ✅
🏷️ Commit: 07a201e73d4cdea9e93d7233697063c3717be6bf
▶️ Tests: 39317 executed
⚪️ Checks: 44/44 completed
---
_Learn more about TestLens at [testlens.app](https://testlens.app)._
--
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@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not close an externally-supplied MongoClient in GORM for MongoDB [grails-core]
Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on PR #15743:
URL: https://github.com/apache/grails-core/pull/15743#issuecomment-4762779537
I went through #15678's current diff (100 files): it's entirely in `grails-data-hibernate5`/`grails-data-hibernate7` (plus graphql and gradle), and the datastore-creation rework there is on the Hibernate datastores. It doesn't touch `DefaultConnectionSource` or anything else in `grails-datastore-core`, nor `MongoDatastore` — the files this PR changes — so there's no file overlap and this rebases cleanly when #15678 lands. The change here is also additive (a new `DefaultConnectionSource` constructor; the existing one is unchanged), so it doesn't alter the creation path for stores that don't opt in.
--
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@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not close an externally-supplied MongoClient in GORM for MongoDB [grails-core]
Posted by "matrei (via GitHub)" <gi...@apache.org>.
matrei commented on code in PR #15743:
URL: https://github.com/apache/grails-core/pull/15743#discussion_r3461874854
##########
grails-data-mongodb/boot-plugin/src/test/groovy/org/grails/datastore/gorm/mongodb/boot/autoconfigure/MongoDbGormAutoConfigurationCloseSpec.groovy:
##########
Review Comment:
- What happens to feature method names if you remove the beginning "test "? I think it reads really good then as a statement of the expected behavior.
- Use `def` for local variables where the type can be inferred.
- Use single qoutes for strings.
##########
grails-data-mongodb/core/src/test/groovy/org/grails/datastore/mapping/mongo/MongoDatastoreExternalClientSpec.groovy:
##########
Review Comment:
Same comments a for `MongoDbGormAutoConfigurationCloseSpec`.
##########
grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/core/connections/DefaultConnectionSourceSpec.groovy:
##########
Review Comment:
Same comments as in `MongoDbGormAutoConfigurationCloseSpec`.
--
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@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not close an externally-supplied MongoClient in GORM for MongoDB [grails-core]
Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on code in PR #15743:
URL: https://github.com/apache/grails-core/pull/15743#discussion_r3463827267
##########
grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/core/connections/DefaultConnectionSourceSpec.groovy:
##########
Review Comment:
fixed
##########
grails-data-mongodb/core/src/test/groovy/org/grails/datastore/mapping/mongo/MongoDatastoreExternalClientSpec.groovy:
##########
Review Comment:
fixed
--
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@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not close an externally-supplied MongoClient in GORM for MongoDB [grails-core]
Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole merged PR #15743:
URL: https://github.com/apache/grails-core/pull/15743
--
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@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org