Closed Vishwamithra37 closed 9 months ago
This update enhances the resilience and reliability of the MongoDB connection in the MongoDBStorage
class by significantly increasing the timeouts for server selection and connection establishment. By adjusting the timeout values from 1 second to 10 seconds, the system aims to reduce potential issues related to brief network interruptions or slow server responses, ensuring a smoother operation and better user experience.
File | Change Summary |
---|---|
limits/aio/storage/mongodb.py |
Increased serverSelectionTimeoutMS and connectTimeoutMS from 1000ms to 10000ms in DEFAULT_OPTIONS . |
πβ¨
In the code's garden, under the moon's soft glow,
A rabbit hopped, with changes in tow.
"Let's wait a bit longer," it whispered with glee,
For connections to bloom, like flowers, you see.
Tenfold patience, now the norm,
Ensuring data flows, through calm and storm.
π±ππΎπβ¨
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
@Vishwamithra37 that default value is too high - if in your setup that is expected why not pass it in explicitly?
All modified and coverable lines are covered by tests :white_check_mark:
Comparison is base (
f1fe9f3
) 96.83% compared to head (90442cf
) 96.83%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@Vishwamithra37 that default value is too high - if in your setup that is expected why not pass it in explicitly?
I believe 10s is okay. Because of the following reasons:
In my and many setups I know where flask-limiter is used, (a wrapper which uses limits library), it is not obvious as to where and how to pass on the connection options for the Database.
To solve this - I think the better solution would be to improve the documentation in flask-limiter (and even here in limits) to make it clearer what the defaults are and how to provide ones own configuration.
ServerSelectionTimeoutError on mongo replica set using pymongo
The error you shared above seems to be referring to a misconfiguration rather than an actual timeout?
ServerSelectionTimeoutError on mongo replica set using pymongo
The error you shared above seems to be referring to a misconfiguration rather than an actual timeout?
My main concern is that it is redundant to make the user specify everything two times, one for their original application and one for their limits library And 1 second is not the standard. And 10s is fine because in case of production/developing connection failure, I'm 100% sure 10s is somewhat equal to 1s as it will crash the application anyway. And the developer would rather give mongodb some time than quickly crash the application by default. (From first hand experience.)
The mongodb forum answers: https://www.mongodb.com/community/forums/t/what-is-the-recommended-value-for-the-serverselectiontimeoutms-setting-for-atlas/149806
Scale Grid answers: https://scalegrid.io/blog/mongodb-timeout-settings/#:~:text=By%20default%2C%20this%20timeout%20is,this%20setting%20does%20affect%20performance.
ServerSelectionTimeoutError on mongo replica set using pymongo
The error you shared above seems to be referring to a misconfiguration rather than an actual timeout?
It is also important to understand that timeout should be long enough by default to make the library more stable rather than quickly go into error mode. As mentioned, timeout is the Maxiumum time its gonna wait for the transaction/CRUD/Connection to stabilize and reconnect to be done. If the connection is stable enough, this shouldnt be an issue. And in case of sudden mishaps, the system should be able to at least wait for the minimum time required for the connection to resolve itself. (Both in case of Mongodb and other SQL dbs). A quick connect and reconnect should not directly impact any application (under 10s).
And 1 second is not the standard.
Fair enough. I'd like to propose however, instead of setting a higher timeout by default, how about we just remove the DEFAULT_OPTIONS
entirely and leave it to the defaults of the underlying pymongo / motor clients?
And 1 second is not the standard.
Fair enough. I'd like to propose however, instead of setting a higher timeout by default, how about we just remove the
DEFAULT_OPTIONS
entirely and leave it to the defaults of the underlying pymongo / motor clients?
Yes!, that sounds like a good way to handle it too :) . I think we should proceed with removing the default options altogether.
Thanks for the input and suggestions. Could we close this PR in favour of 55cdfb9a3731a46fcb768fd5dad93dc99534909b?
Thanks for the input and suggestions. Could we close this PR in favour of 55cdfb9a3731a46fcb768fd5dad93dc99534909b?
Yep please do :)
Summary by CodeRabbit