mongodb/mongo-ruby-driver

View on GitHub
lib/mongo/server/connection_pool.rb

Summary

Maintainability
F
5 days
Test Coverage

File connection_pool.rb has 728 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Mongo
  class Server

    # Represents a connection pool for server connections.
    #
Severity: Major
Found in lib/mongo/server/connection_pool.rb - About 1 day to fix

    Class ConnectionPool has 55 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class ConnectionPool
          include Loggable
          include Monitoring::Publishable
          extend Forwardable
    
    
    Severity: Major
    Found in lib/mongo/server/connection_pool.rb - About 7 hrs to fix

      Method initialize has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def initialize(server, options = {})
              unless server.is_a?(Server)
                raise ArgumentError, 'First argument must be a Server instance'
              end
              options = options.dup
      Severity: Minor
      Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

        Method close has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

              def close(options = nil)
                return if closed?
        
                options ||= {}
        
        
        Severity: Minor
        Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method close_idle_sockets has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

              def close_idle_sockets
                return if closed?
                return unless max_idle_time
        
                @lock.synchronize do
        Severity: Minor
        Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method get_connection has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

              def get_connection(pid, connection_global_id)
                if connection = next_available_connection(connection_global_id)
                  unless valid_available_connection?(connection, pid, connection_global_id)
                    return nil
                  end
        Severity: Minor
        Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method do_check_in has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

              def do_check_in(connection)
                # When a connection is interrupted it is checked back into the pool
                # and closed. The operation that was using the connection before it was
                # interrupted will attempt to check it back into the pool, and we
                # should ignore it since its already been closed and removed from the pool.
        Severity: Minor
        Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method initialize has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

              def initialize(server, options = {})
                unless server.is_a?(Server)
                  raise ArgumentError, 'First argument must be a Server instance'
                end
                options = options.dup
        Severity: Minor
        Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method do_check_in has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def do_check_in(connection)
                # When a connection is interrupted it is checked back into the pool
                # and closed. The operation that was using the connection before it was
                # interrupted will attempt to check it back into the pool, and we
                # should ignore it since its already been closed and removed from the pool.
        Severity: Minor
        Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

          Method close_available_connections has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

                def close_available_connections(service_id)
                  if @server.load_balancer? && service_id
                    loop do
                      conn = @available_connections.detect do |conn|
                        conn.service_id == service_id &&
          Severity: Minor
          Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method do_clear has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

                def do_clear(options = nil)
                  check_invariants
          
                  service_id = options && options[:service_id]
          
          
          Severity: Minor
          Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method create_and_add_connection has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

                def create_and_add_connection
                  connection = nil
          
                  @lock.synchronize do
                    if !closed? && @ready &&
          Severity: Minor
          Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method get_connection has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def get_connection(pid, connection_global_id)
                  if connection = next_available_connection(connection_global_id)
                    unless valid_available_connection?(connection, pid, connection_global_id)
                      return nil
                    end
          Severity: Minor
          Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

            Method create_and_add_connection has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def create_and_add_connection
                    connection = nil
            
                    @lock.synchronize do
                      if !closed? && @ready &&
            Severity: Minor
            Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

              Method do_clear has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def do_clear(options = nil)
                      check_invariants
              
                      service_id = options && options[:service_id]
              
              
              Severity: Minor
              Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

                Method wait_for_connection has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                      def wait_for_connection(connection_global_id, deadline)
                        connection = nil
                        while connection.nil?
                          # The second gate to checking out a connection. Make sure 1) there
                          # exists an available connection and 2) we are under max_connecting.
                Severity: Minor
                Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method retrieve_and_connect_connection has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                      def retrieve_and_connect_connection(connection_global_id)
                        deadline = Utils.monotonic_time + wait_timeout
                        connection = nil
                
                        @lock.synchronize do
                Severity: Minor
                Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method close has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def close(options = nil)
                        return if closed?
                
                        options ||= {}
                
                
                Severity: Minor
                Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

                  Method check_invariants has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                        def check_invariants
                          return unless Lint.enabled?
                  
                          # Server summary calls pool summary which requires pool lock -> deadlock.
                          # Obtain the server summary ahead of time.
                  Severity: Minor
                  Found in lib/mongo/server/connection_pool.rb - About 45 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method valid_available_connection? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                        def valid_available_connection?(connection, pid, connection_global_id)
                          if connection.pid != pid
                            log_warn("Detected PID change - Mongo client should have been reconnected (old pid #{connection.pid}, new pid #{pid}")
                            connection.disconnect!(reason: :stale)
                            @populate_semaphore.signal
                  Severity: Minor
                  Found in lib/mongo/server/connection_pool.rb - About 35 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method ready has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                        def ready
                          raise_if_closed!
                  
                          # TODO: Add this back in RUBY-3174.
                          # if Lint.enabled?
                  Severity: Minor
                  Found in lib/mongo/server/connection_pool.rb - About 25 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Similar blocks of code found in 3 locations. Consider refactoring.
                  Open

                          if options[:min_size] && options[:min_pool_size] && options[:min_size] != options[:min_pool_size]
                            raise ArgumentError, "Min size #{options[:min_size]} is not identical to min pool size #{options[:min_pool_size]}"
                          end
                  Severity: Minor
                  Found in lib/mongo/server/connection_pool.rb and 2 other locations - About 20 mins to fix
                  lib/mongo/server/connection_pool.rb on lines 110..112
                  lib/mongo/server/connection_pool.rb on lines 113..115

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 28.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 3 locations. Consider refactoring.
                  Open

                          if options[:max_size] && options[:max_pool_size] && options[:max_size] != options[:max_pool_size]
                            raise ArgumentError, "Max size #{options[:max_size]} is not identical to max pool size #{options[:max_pool_size]}"
                          end
                  Severity: Minor
                  Found in lib/mongo/server/connection_pool.rb and 2 other locations - About 20 mins to fix
                  lib/mongo/server/connection_pool.rb on lines 107..109
                  lib/mongo/server/connection_pool.rb on lines 113..115

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 28.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 3 locations. Consider refactoring.
                  Open

                          if options[:wait_timeout] && options[:wait_queue_timeout] && options[:wait_timeout] != options[:wait_queue_timeout]
                            raise ArgumentError, "Wait timeout #{options[:wait_timeout]} is not identical to wait queue timeout #{options[:wait_queue_timeout]}"
                          end
                  Severity: Minor
                  Found in lib/mongo/server/connection_pool.rb and 2 other locations - About 20 mins to fix
                  lib/mongo/server/connection_pool.rb on lines 107..109
                  lib/mongo/server/connection_pool.rb on lines 110..112

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 28.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  There are no issues that match your filters.

                  Category
                  Status