This is an automated email from the ASF dual-hosted git repository.

csringhofer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git


The following commit(s) were added to refs/heads/master by this push:
     new 1b388918d IMPALA-14750: Reduce leaked socket warnings in pytest - part 
1
1b388918d is described below

commit 1b388918d514183a41bcc4e2a154551a19beeb42
Author: Csaba Ringhofer <[email protected]>
AuthorDate: Tue Feb 17 23:41:12 2026 +0100

    IMPALA-14750: Reduce leaked socket warnings in pytest - part 1
    
    Fixes some of the common causes of warnings like
    ResourceWarning: unclosed <socket.socket fd=40, 
family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, 
laddr=('127.0.0.1', 45860), raddr=('127.0.0.1', 21050)>
    
    The fix is not perfect, e.g. it doesn't close the socket
    if there is a test failure in some cases. The goal is to quickly
    reduce the noise in tests, as this is a possible cause
    behind some issues (e.g. running out of memory when publishing
    results).
    
    Change-Id: I95a3d0fbb4053bf5ab3e83175b38481bb15bf379
    Reviewed-on: http://gerrit.cloudera.org:8080/23992
    Reviewed-by: Impala Public Jenkins <[email protected]>
    Tested-by: Impala Public Jenkins <[email protected]>
---
 tests/common/impala_connection.py |  3 ++-
 tests/common/impala_test_suite.py |  5 +++++
 tests/custom_cluster/test_ipv6.py | 10 +++++-----
 tests/query_test/test_udfs.py     |  6 +++---
 4 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/tests/common/impala_connection.py 
b/tests/common/impala_connection.py
index 4547c15aa..f2bf2424b 100644
--- a/tests/common/impala_connection.py
+++ b/tests/common/impala_connection.py
@@ -637,7 +637,8 @@ class ImpylaHS2Connection(ImpalaConnection):
     # Remove all async cursors.
     self.__async_cursors = list()
     try:
-      self.__impyla_conn.close()
+      if self.__impyla_conn:
+        self.__impyla_conn.close()
     except AttributeError as e:
       # When the HTTP endpoint restarts, Thrift HTTP will close the endpoint 
and calling
       # close() will result in an exception.
diff --git a/tests/common/impala_test_suite.py 
b/tests/common/impala_test_suite.py
index 233465a0d..fe59cd024 100644
--- a/tests/common/impala_test_suite.py
+++ b/tests/common/impala_test_suite.py
@@ -811,6 +811,7 @@ class ImpalaTestSuite(BaseTestSuite):
       if user:
         # Create a new client so the session will use the new username.
         target_impalad_client = self.create_impala_client(protocol=protocol)
+      client_needs_cleanup = user is not None
       query_options_changed = []
       try:
         for query in query.split(';'):
@@ -826,6 +827,8 @@ class ImpalaTestSuite(BaseTestSuite):
       finally:
         if len(query_options_changed) > 0:
           self.__restore_query_options(query_options_changed, 
target_impalad_client)
+        if client_needs_cleanup:
+          target_impalad_client.close()
       return result
 
     def __exec_in_hive(query, user=None):
@@ -1029,6 +1032,8 @@ class ImpalaTestSuite(BaseTestSuite):
     # Revert target_impalad_clients back to default database.
     for impalad_client in target_impalad_clients:
       ImpalaTestSuite.__change_client_database(impalad_client, 
db_name='default')
+      if multiple_impalad:
+        impalad_client.close()
 
   def get_query_lineage(self, query_id, lineage_dir):
     """Walks through the lineage files in lineage_dir to look for a given 
query_id.
diff --git a/tests/custom_cluster/test_ipv6.py 
b/tests/custom_cluster/test_ipv6.py
index 00c77dce8..f014758e7 100644
--- a/tests/custom_cluster/test_ipv6.py
+++ b/tests/custom_cluster/test_ipv6.py
@@ -92,11 +92,11 @@ class TestIPv6Base(CustomClusterTestSuite):
       port = self._get_default_port(proto)
       host_port = "%s:%d" % (host, port)
       use_ssl = self.ca_cert is not None
-      conn = create_connection(host_port, protocol=proto, use_ssl=use_ssl)
-      conn.connect()
-      assert not expected_errors
-      res = conn.execute("select 1")
-      assert res.data == ["1"]
+      with create_connection(host_port, protocol=proto, use_ssl=use_ssl) as 
conn:
+        conn.connect()
+        assert not expected_errors
+        res = conn.execute("select 1")
+        assert res.data == ["1"]
     except Exception as ex:
       for err in expected_errors:
         if err in str(ex): return
diff --git a/tests/query_test/test_udfs.py b/tests/query_test/test_udfs.py
index 43c08f1aa..0568c094f 100644
--- a/tests/query_test/test_udfs.py
+++ b/tests/query_test/test_udfs.py
@@ -49,9 +49,9 @@ class TestUdfBase(ImpalaTestSuite):
   def _run_query_all_impalads(self, exec_options, query, expected):
     impala_cluster = ImpalaCluster.get_e2e_test_cluster()
     for impalad in impala_cluster.impalads:
-      client = impalad.service.create_hs2_client()
-      result = self.execute_query_expect_success(client, query, exec_options)
-      assert result.data == expected, impalad
+      with impalad.service.create_hs2_client() as client:
+        result = self.execute_query_expect_success(client, query, exec_options)
+        assert result.data == expected, impalad
 
   def _load_functions(self, template, vector, database, location):
     queries = template.format(database=database, location=location)

Reply via email to