lib/puma/server.rb

Summary

Maintainability
F
4 days
Test Coverage

File server.rb has 420 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'stringio'

require 'puma/thread_pool'
require 'puma/const'
require 'puma/events'
Severity: Minor
Found in lib/puma/server.rb - About 6 hrs to fix

    Method process_client has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

        def process_client(client, buffer)
          # Advertise this server into the thread
          Thread.current[ThreadLocalKey] = self
    
          clean_thread_locals = @options[:clean_thread_locals]
    Severity: Minor
    Found in lib/puma/server.rb - About 5 hrs 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 handle_servers has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

        def handle_servers
          begin
            check = @check
            sockets = [check] + @binder.ios
            pool = @thread_pool
    Severity: Minor
    Found in lib/puma/server.rb - About 4 hrs 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

    Class Server has 29 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Server
    
        include Puma::Const
        include Request
        extend Forwardable
    Severity: Minor
    Found in lib/puma/server.rb - About 3 hrs to fix

      Method graceful_shutdown has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          def graceful_shutdown
            if @options[:shutdown_debug]
              threads = Thread.list
              total = threads.size
      
      
      Severity: Minor
      Found in lib/puma/server.rb - About 3 hrs 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 process_client has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def process_client(client, buffer)
            # Advertise this server into the thread
            Thread.current[ThreadLocalKey] = self
      
            clean_thread_locals = @options[:clean_thread_locals]
      Severity: Major
      Found in lib/puma/server.rb - About 2 hrs to fix

        Method handle_servers has 59 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def handle_servers
              begin
                check = @check
                sockets = [check] + @binder.ios
                pool = @thread_pool
        Severity: Major
        Found in lib/puma/server.rb - About 2 hrs to fix

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

                def closed_socket?(socket)
                  return false unless socket.kind_of? TCPSocket
                  return false unless @precheck_closing
          
                  begin
          Severity: Minor
          Found in lib/puma/server.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 graceful_shutdown has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def graceful_shutdown
                if @options[:shutdown_debug]
                  threads = Thread.list
                  total = threads.size
          
          
          Severity: Minor
          Found in lib/puma/server.rb - About 1 hr to fix

            Method run has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def run(background=true, thread_name: 'server')
                  BasicSocket.do_not_reverse_lookup = true
            
                  @events.fire :state, :booting
            
            
            Severity: Minor
            Found in lib/puma/server.rb - About 1 hr to fix

              Method notify_safely has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def notify_safely(message)
                    @notify << message
                  rescue IOError, NoMethodError, Errno::EPIPE
                    # The server, in another thread, is shutting down
                    Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
              Severity: Minor
              Found in lib/puma/server.rb - About 55 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 cork_socket has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                    def cork_socket(socket)
                      skt = socket.to_io
                      begin
                        skt.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_CORK, 1) if skt.kind_of? TCPSocket
                      rescue IOError, SystemCallError
              Severity: Minor
              Found in lib/puma/server.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 lowlevel_error has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def lowlevel_error(e, env, status=500)
                    if handler = @options[:lowlevel_error_handler]
                      if handler.arity == 1
                        return handler.call(e)
                      elsif handler.arity == 2
              Severity: Minor
              Found in lib/puma/server.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 uncork_socket has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                    def uncork_socket(socket)
                      skt = socket.to_io
                      begin
                        skt.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_CORK, 0) if skt.kind_of? TCPSocket
                      rescue IOError, SystemCallError
              Severity: Minor
              Found in lib/puma/server.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 run has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def run(background=true, thread_name: 'server')
                    BasicSocket.do_not_reverse_lookup = true
              
                    @events.fire :state, :booting
              
              
              Severity: Minor
              Found in lib/puma/server.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 reactor_wakeup has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def reactor_wakeup(client)
                    shutdown = !@queue_requests
                    if client.try_to_finish || (shutdown && !client.can_close?)
                      @thread_pool << client
                    elsif shutdown || client.timeout == 0
              Severity: Minor
              Found in lib/puma/server.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 2 locations. Consider refactoring.
              Open

                    def uncork_socket(socket)
                      skt = socket.to_io
                      begin
                        skt.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_CORK, 0) if skt.kind_of? TCPSocket
                      rescue IOError, SystemCallError
              Severity: Minor
              Found in lib/puma/server.rb and 1 other location - About 25 mins to fix
              lib/puma/server.rb on lines 145..151

              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 29.

              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 2 locations. Consider refactoring.
              Open

                    def cork_socket(socket)
                      skt = socket.to_io
                      begin
                        skt.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_CORK, 1) if skt.kind_of? TCPSocket
                      rescue IOError, SystemCallError
              Severity: Minor
              Found in lib/puma/server.rb and 1 other location - About 25 mins to fix
              lib/puma/server.rb on lines 154..160

              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 29.

              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