Commit dcac3f5
committed
[SPARK-52076][CONNECT] Explicitly closes ExecutePlanResponseReattachableIterator after usage
### What changes were proposed in this pull request?
This PR proposes to explicitly close `ExecutePlanResponseReattachableIterator` after usage.
### Why are the changes needed?
There might be a corner case deadlock as below. The main reason is that the point of calling `__del__` can be arbitrary and it could depend on each other.
```
Dumping Threads....
File "/.../versions/3.9.21/lib/python3.9/threading.py", line 937, in _bootstrap
self._bootstrap_inner()
File "/.../versions/3.9.21/lib/python3.9/threading.py", line 980, in _bootstrap_inner
self.run()
File "/.../versions/3.9.21/lib/python3.9/threading.py", line 917, in run
self._target(*self._args, **self._kwargs)
File "/.../versions/3.9.21/lib/python3.9/concurrent/futures/thread.py", line 85, in _worker
del work_item
File "/.../python/pyspark/sql/connect/client/reattach.py", line 347, in __del__
return self.close()
File "/.../python/pyspark/sql/connect/client/reattach.py", line 343, in close
self._release_all()
File "/.../python/pyspark/sql/connect/client/reattach.py", line 241, in _release_all
with self._lock:
---------------
File "/.../versions/3.9.21/lib/python3.9/threading.py", line 937, in _bootstrap
self._bootstrap_inner()
File "/.../versions/3.9.21/lib/python3.9/threading.py", line 980, in _bootstrap_inner
self.run()
File "/.../versions/3.9.21/lib/python3.9/threading.py", line 917, in run
self._target(*self._args, **self._kwargs)
File "/.../versions/pyspark-dev-3.9/lib/python3.9/site-packages/grpc/_channel.py", line 1751, in channel_spin
event = state.channel.next_call_event()
---------------
File "<string>", line 44, in <module>
File "/.../python/pyspark/sql/connect/session.py", line 890, in stop
self.client.close()
File "/.../python/pyspark/sql/connect/client/core.py", line 1234, in close
ExecutePlanResponseReattachableIterator.shutdown()
File "/.../python/pyspark/sql/connect/client/reattach.py", line 82, in shutdown
cls._get_or_create_release_thread_pool().shutdown()
File "/.../versions/3.9.21/lib/python3.9/concurrent/futures/thread.py", line 235, in shutdown
t.join()
File "/.../versions/3.9.21/lib/python3.9/threading.py", line 1060, in join
self._wait_for_tstate_lock()
File "/.../versions/3.9.21/lib/python3.9/threading.py", line 1080, in _wait_for_tstate_lock
if lock.acquire(block, timeout):
File "<string>", line 1, in <module>
File "<string>", line 1, in <module>
```
### Does this PR introduce _any_ user-facing change?
For corner cases, yes. There might be a deadlock, and this PR fixes it.
### How was this patch tested?
Difficult to test. It was more to just remove the cause itself.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #50855 from HyukjinKwon/explicitly-close-generator.
Authored-by: Hyukjin Kwon <gurwls223@apache.org>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>1 parent b50690a commit dcac3f5
2 files changed
+10
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1374 | 1374 | | |
1375 | 1375 | | |
1376 | 1376 | | |
1377 | | - | |
1378 | | - | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
1379 | 1382 | | |
1380 | 1383 | | |
1381 | 1384 | | |
| |||
1531 | 1534 | | |
1532 | 1535 | | |
1533 | 1536 | | |
1534 | | - | |
1535 | | - | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
1536 | 1542 | | |
1537 | 1543 | | |
1538 | 1544 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
0 commit comments