{"action":"created","issue":{"url":"https://api.github.com/repos/mongoid/mongoid/issues/4109","labels_url":"https://api.github.com/repos/mongoid/mongoid/issues/4109/labels{/name}","comments_url":"https://api.github.com/repos/mongoid/mongoid/issues/4109/comments","events_url":"https://api.github.com/repos/mongoid/mongoid/issues/4109/events","html_url":"https://github.com/mongoid/mongoid/issues/4109","id":91825612,"number":4109,"title":"Mongoid 5 & Sidekiq => many open connections","user":{"login":"256dpi","id":696886,"avatar_url":"https://avatars.githubusercontent.com/u/696886?v=3","gravatar_id":"","url":"https://api.github.com/users/256dpi","html_url":"https://github.com/256dpi","followers_url":"https://api.github.com/users/256dpi/followers","following_url":"https://api.github.com/users/256dpi/following{/other_user}","gists_url":"https://api.github.com/users/256dpi/gists{/gist_id}","starred_url":"https://api.github.com/users/256dpi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/256dpi/subscriptions","organizations_url":"https://api.github.com/users/256dpi/orgs","repos_url":"https://api.github.com/users/256dpi/repos","events_url":"https://api.github.com/users/256dpi/events{/privacy}","received_events_url":"https://api.github.com/users/256dpi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-06-29T14:45:42Z","updated_at":"2015-06-29T22:00:36Z","closed_at":null,"body":"I gave mongoid 5 a try in my app.\r\n\r\nThe rails side is working without problems, but the sidekiq process is constantly opening connections.\r\nOnly if I restart the process, the connections get closed.\r\n\r\nI get the value from mongodb `serverStatus.connections.current` metric.\r\n\r\nI use the following client settings in `mongoid.yml`:\r\n\r\n```yaml\r\nmax_pool_size: 100\r\nmin_pool_size: 30\r\n```\r\n\r\nAs I only upgraded the mongoid gem, I assume the problem is not depending on sidekiq."},"comment":{"url":"https://api.github.com/repos/mongoid/mongoid/issues/comments/116859723","html_url":"https://github.com/mongoid/mongoid/issues/4109#issuecomment-116859723","issue_url":"https://api.github.com/repos/mongoid/mongoid/issues/4109","id":116859723,"user":{"login":"256dpi","id":696886,"avatar_url":"https://avatars.githubusercontent.com/u/696886?v=3","gravatar_id":"","url":"https://api.github.com/users/256dpi","html_url":"https://github.com/256dpi","followers_url":"https://api.github.com/users/256dpi/followers","following_url":"https://api.github.com/users/256dpi/following{/other_user}","gists_url":"https://api.github.com/users/256dpi/gists{/gist_id}","starred_url":"https://api.github.com/users/256dpi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/256dpi/subscriptions","organizations_url":"https://api.github.com/users/256dpi/orgs","repos_url":"https://api.github.com/users/256dpi/repos","events_url":"https://api.github.com/users/256dpi/events{/privacy}","received_events_url":"https://api.github.com/users/256dpi/received_events","type":"User","site_admin":false},"created_at":"2015-06-29T22:00:36Z","updated_at":"2015-06-29T22:00:36Z","body":"I have a main worker that gets scheduled by a clockwork process every 30 minutes:\r\n\r\n```ruby\r\nclass RetentionLimiterScheduler\r\n  include Sidekiq::Worker\r\n\r\n  sidekiq_options retry: false\r\n\r\n  def perform\r\n    Namespace.all.each_with_index do |namespace, i|\r\n      RetentionLimiter.perform_in((i * 10).seconds, namespace.id.to_s)\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nThe other worker does the actual job:\r\n\r\n```ruby\r\nclass RetentionLimiter\r\n  include Sidekiq::Worker\r\n\r\n  def perform(namespace_id)\r\n    RetentionLimitation.new(Namespace.find(namespace_id)).limit!\r\n  end\r\nend\r\n```\r\n\r\nThe service class 'RetentionLimitation' does just some things like:\r\n\r\n```ruby\r\n@namespace.messages.where(some_filters).delete_all\r\n```\r\n\r\nI haven't tried `Mongoid.disconnect_client`, is it threadsafe?"}}