← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1573949] [NEW] lbaas: better to close a socket explicitly rather than implicitly when they are garbage-collected

 

Public bug reported:

https://github.com/openstack/neutron-
lbaas/blob/master/neutron_lbaas/services/loadbalancer/drivers/haproxy/namespace_driver.py#L205
:

    def _get_stats_from_socket(self, socket_path, entity_type):
        try:
            s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            s.connect(socket_path)
            s.send('show stat -1 %s -1\n' % entity_type)
            raw_stats = ''
            chunk_size = 1024
            while True:
                chunk = s.recv(chunk_size)
                raw_stats += chunk
                if len(chunk) < chunk_size:
                    break

            return self._parse_stats(raw_stats)
        except socket.error as e:
            LOG.warning(_LW('Error while connecting to stats socket: %s'), e)
            return {}

in this function, a socket connection is created but it is not closed
explicitly. It is better to close it when all things have been done

** Affects: neutron
     Importance: Undecided
     Assignee: ding bo (longddropt)
         Status: New

** Summary changed:

- lbaas: better to close a socket explicitly rather than implicitly when they are  they are garbage-collected
+ lbaas: better to close a socket explicitly rather than implicitly when they are garbage-collected

** Changed in: neutron
     Assignee: (unassigned) => ding bo (longddropt)

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to neutron.
https://bugs.launchpad.net/bugs/1573949

Title:
  lbaas: better to close a socket explicitly rather than implicitly when
  they are garbage-collected

Status in neutron:
  New

Bug description:
  https://github.com/openstack/neutron-
  lbaas/blob/master/neutron_lbaas/services/loadbalancer/drivers/haproxy/namespace_driver.py#L205
  :

      def _get_stats_from_socket(self, socket_path, entity_type):
          try:
              s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
              s.connect(socket_path)
              s.send('show stat -1 %s -1\n' % entity_type)
              raw_stats = ''
              chunk_size = 1024
              while True:
                  chunk = s.recv(chunk_size)
                  raw_stats += chunk
                  if len(chunk) < chunk_size:
                      break

              return self._parse_stats(raw_stats)
          except socket.error as e:
              LOG.warning(_LW('Error while connecting to stats socket: %s'), e)
              return {}

  in this function, a socket connection is created but it is not closed
  explicitly. It is better to close it when all things have been done

To manage notifications about this bug go to:
https://bugs.launchpad.net/neutron/+bug/1573949/+subscriptions


Follow ups