Skip to content

Commit ebb5ae2

Browse files
committed
Merge remote-tracking branch 'origin/main' into kevinjqliu/spark4-remove-filterwarnings
2 parents 2313e51 + 34265fb commit ebb5ae2

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

pyiceberg/catalog/hive.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ def __enter__(self) -> Client:
185185
try:
186186
self._transport.open()
187187
except (TypeError, TTransport.TTransportException):
188+
# Close the old transport before reinitializing to prevent resource leaks
189+
try:
190+
self._transport.close()
191+
except Exception:
192+
pass
188193
# reinitialize _transport
189194
self._transport = self._init_thrift_transport()
190195
self._transport.open()

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,6 @@ markers = [
347347
# Turns a warning into an error
348348
filterwarnings = [
349349
"error",
350-
"ignore:A plugin raised an exception during an old-style hookwrapper teardown.",
351-
"ignore:unclosed <socket.socket",
352350
]
353351

354352
[tool.black]

tests/catalog/test_hive.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def __init__(self, socket: thrift.transport.TSocket.TServerSocket, response: byt
204204
self._response = response
205205
self._port = None
206206
self._port_bound = threading.Event()
207+
self._clients: list[thrift.transport.TSocket.TSocket] = [] # Track accepted client connections
207208

208209
def run(self) -> None:
209210
self._socket.listen()
@@ -222,6 +223,7 @@ def run(self) -> None:
222223
try:
223224
client = self._socket.accept()
224225
if client:
226+
self._clients.append(client) # Track the client
225227
client.write(self._response)
226228
client.flush()
227229
except Exception:
@@ -233,6 +235,12 @@ def port(self) -> Optional[int]:
233235
return self._port
234236

235237
def close(self) -> None:
238+
# Close all client connections first
239+
for client in self._clients:
240+
try:
241+
client.close()
242+
except Exception:
243+
pass
236244
self._socket.close()
237245

238246

@@ -1392,6 +1400,7 @@ def test_create_hive_client_with_kerberos_using_context_manager(
13921400
with client as open_client:
13931401
assert open_client._iprot.trans.isOpen()
13941402

1403+
assert not open_client._iprot.trans.isOpen()
13951404
# Use the context manager a second time to see if
13961405
# closing and re-opening work as expected.
13971406
with client as open_client:

0 commit comments

Comments
 (0)