Do not close an externally-supplied MongoClient in GORM for MongoDB#15743
Do not close an externally-supplied MongoClient in GORM for MongoDB#15743codeconsole wants to merge 1 commit into
Conversation
|
Why are you using gorm's mongo and spring's mongo? |
|
This PR doesn't introduce any GORM↔Spring Mongo mixing — |
|
I'm sure this is not a totally rational fear, but I would point to #15678 since there was reworking of datastore creation |
GORM's connection-source shutdown closes any Closeable source, and a MongoClient is Closeable, so a client handed to GORM (for example a Spring-managed bean, or one passed to new MongoDatastore(mongoClient, ...)) was closed when the datastore shut down - double-closing a client whose lifecycle is owned elsewhere. DefaultConnectionSource now supports a non-closeable mode (a new constructor plus isCloseable()); the existing constructor is unchanged. MongoDatastore wraps an externally-supplied client as non-closeable so GORM no longer closes a client it did not create, and MongoDbGormAutoConfiguration closes only the client it created itself. GORM still closes clients it creates from grails.mongodb.* configuration. The only behavior change affects callers that relied on MongoDatastore.close() to also close a client they passed in; they must now close it themselves. This is documented in the upgrade notes.
735529e to
d95eb44
Compare
✅ All tests passed ✅🏷️ Commit: d95eb44 Learn more about TestLens at testlens.app. |
|
I went through #15678's current diff (100 files): it's entirely in |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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 🚀 New features to boost your workflow:
|
What
GORM's connection-source shutdown closes any
Closeablesource, andcom.mongodb.client.MongoClientisCloseable, so a client handed to GORM — a Spring-managed bean, or one passed tonew 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
MongoClientit did not create:DefaultConnectionSourcegains a non-closeable mode (new 4-arg constructor +isCloseable()); the existing constructor is unchanged, so there is no behavior change for current callers.MongoDatastore.createDefaultConnectionSourceswraps an externally-supplied client as non-closeable.MongoDbGormAutoConfigurationimplementsDisposableBeanand 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
MongoClientbean).MongoClientacross 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 anAutoCloseablewhen 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.