Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5255

Unexpected client close with Runtime Persistence

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 8.0.1
    • Affects Version/s: 7.2.5
    • Component/s: Persistence
    • Labels:
      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:

      1. at the beginning of Post.with(), when there is no secondary_preferred client, the new client will be created
      2. at the end of Post.with() block, secondary_preferred client is closed
      3. 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!

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            keiko@netlify.com Keiko Oda
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: