Do not close an externally-supplied MongoClient in GORM for MongoDB#15743
Open
codeconsole wants to merge 1 commit into
Open
Do not close an externally-supplied MongoClient in GORM for MongoDB#15743codeconsole wants to merge 1 commit into
codeconsole wants to merge 1 commit into
Conversation
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.
✅ All tests passed ✅🏷️ Commit: 735529e Learn more about TestLens at testlens.app. |
Contributor
|
Why are you using gorm's mongo and spring's mongo? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.