-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: 7.2.5
-
Component/s: Persistence
-
None
We're using the Runtime Persistence to make a query with the secondary preferred read mode like the following:
posts = Post.with(client: :secondary_preferred) do Post.all end # do something else comments = Comment.with(client: :secondary_preferred) do Comment.all end
Outside of this, we use the default client (which doesn't have the secondary preferred read mode). Based on the documentation (https://docs.mongodb.com/mongoid/current/tutorials/mongoid-persistence/#runtime-persistence-options), this persistence context will create a new client and that client will be closed at the end of the block.
However, we're observing the following behavior:
- at the beginning of Post.with(), when there is no secondary_preferred client, the new client will be created
- at the end of Post.with() block, secondary_preferred client is closed
- within Comment.with() block, there is secondary_preferred client (just being closed), so no new client will be made, and it will be reused
This is problematic, because at the step2's client closing, the monitoring for the servers will also stop and they become a NO-MONITORING state. The secondary_preferred client will continue to be used, and as that remains at the process level, this NO-MONITORING state continues until the process dies. When any stepdown happens with NO-MONITORING, it can't pick up the correct primary.
Please let me know if I can provide more info, I have a simple reproducible app as well if that helps. Thanks!