Conversation
Use a 5 s server selection timeout instead of the driver's 30 s when the connection string does not set serverSelectionTimeoutMS; a value in the connection string always wins.
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.
Type: bugfix
Issue
The MongoDB client is built from the connection string with the driver defaults, so server selection waits 30 s. Every storefront request reads the customer from MongoDB without a cache, so while MongoDB is unreachable every non-static request hangs for 30 s before it fails. Waiting requests pile up, and the single-flight cache lock makes later waiters of the same key wait for each earlier attempt in turn.
Solution
StartupApplication.CreateMongoClientSettingsbuilds the client settings as before, and setsServerSelectionTimeoutto 5 s when the connection string does not giveserverSelectionTimeoutMS. A value in the connection string always wins, including an explicit30000. The check reads the parsedConnectionString.ServerSelectionTimeout(nullable), not the value onMongoClientSettings, because that one already holds the 30 s default when nothing was given.The option is described next to
ConnectionStringsin the fourappsettings.jsonfiles (storefront, Admin, Store, Vendor).Not changed:
timeoutMS, CSOT) is not public in driver 3.12 (MongoClientSettings.Timeoutis internal), so it is neither set nor documented.MongoPluginStateStore, the installer'sDatabaseFactoryContext, and the connection-string constructors ofMongoRepositoryandMongoStoreFilesContext.Breaking changes
Installations whose connection string does not set
serverSelectionTimeoutMSnow give up after 5 s instead of 30 s. A replica set that needs longer to elect a new primary should set the value explicitly, e.g....?serverSelectionTimeoutMS=15000.Testing
dotnet test src/Tests/Grand.Infrastructure.Tests --filter "FullyQualifiedName~Startup": the newMongoClientSettingsTestscover the default (5 s), an explicit value (15 s), an explicit driver default (30 s), and other options left as given.CreateMongoClientSettingsto a closed port (mongodb://127.0.0.1:27999) throwsTimeoutExceptionafter 5.0 s (A timeout occurred after 5014ms selecting a server); with the driver default it is 30 s.dotnet test GrandNode.slnx: everything passes except 2 tests inGrand.Business.Catalog.Testsand 5 inGrand.Business.Checkout.Teststhat failed withcollection dropped(shared test database in the parallel run); both projects pass on their own (1209/1210 with 1 skipped, 1195/1195). They do not use the changed code.