Skip to content

Possible waste of new pooled-connections on application shutdown #160

@ankostis

Description

@ankostis

On python-shutdown of an app using this lib I get these debug logs from these protocol lines:

2017-06-27 10:52:53,489:DEBUG:exchangelib.autodiscover:Domain outlook.com: Closing sessions
2017-06-27 10:52:53,490:DEBUG:exchangelib.protocol:Server outlook.com: Closing sessions
2017-06-27 10:52:53,490:DEBUG:exchangelib.protocol:Closing socket ('1.2.3.4', 24179)
2017-06-27 10:52:53,491:DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): outlook.com
2017-06-27 10:52:53,491:DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): outlook.com
2017-06-27 10:52:53,492:DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): outlook.com
2017-06-27 10:52:53,492:DEBUG:exchangelib.protocol:Server outlook.com: Closing sessions
2017-06-27 10:52:53,492:DEBUG:exchangelib.protocol:Server outlook.office365.com: Closing sessions
2017-06-27 10:52:53,492:DEBUG:exchangelib.protocol:Closing socket ('1.2.3.4', 24183)
2017-06-27 10:52:53,493:DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): outlook.office365.com
2017-06-27 10:52:53,493:DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): outlook.office365.com
2017-06-27 10:52:53,494:DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): outlook.office365.com
  • Could it be that when retrieving the connections from the pool to close them, actually new ones are generated?
  • Wouldn't it be enough to invoke urllib3.connectionpool.HttpConnectionPool.close() , like that?
    def close_socket(self, url):
        # Close underlying socket. This ensures we don't leave stray sockets around after program exit.
        adapter = self.get_adapter(url)
        pool = adapter.get_connection(url)
+         pool.close()
-         for _ in range(pool.pool.qsize()):
-             conn = pool._get_conn()
-             if conn.sock:
-                 log.debug('Closing socket %s', text_type(conn.sock.getsockname()))
-                 conn.sock.shutdown(socket.SHUT_RDWR)
-                 conn.sock.close()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions