Skip to content

Commit

Permalink
ARROW-12622: [Python] Fix segfault in read_csv when not on main thread
Browse files Browse the repository at this point in the history
An uninitialized StopToken caused segfaults if you ever called read_csv with cancellation disabled or when not on the main thread (e.g. if used in a Flight server). If we have a 4.0.1 I think this qualifies as a regression.

Closes apache#10227 from lidavidm/arrow-12622

Authored-by: David Li <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
  • Loading branch information
lidavidm authored and kszucs committed May 17, 2021
1 parent c5ee38c commit dbf16e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/pyarrow/error.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ cdef class SignalStopHandler:
if signal.getsignal(sig) not in (signal.SIG_DFL,
signal.SIG_IGN, None)]

self._stop_token = StopToken()
if not self._signals.empty():
self._stop_token = StopToken()
self._stop_token.init(GetResultValue(
SetSignalStopSource()).token())
self._enabled = True
Expand Down
8 changes: 8 additions & 0 deletions python/pyarrow/tests/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,14 @@ def signal_from_thread():
assert isinstance(e, pa.ArrowCancelled)
assert e.signum == signal.SIGINT

def test_cancellation_disabled(self):
# ARROW-12622: reader would segfault when the cancelling signal
# handler was not enabled (e.g. if disabled, or if not on the
# main thread)
t = threading.Thread(target=lambda: self.read_bytes(b"f64\n0.1"))
t.start()
t.join()


class TestSerialCSVRead(BaseTestCSVRead, unittest.TestCase):

Expand Down

0 comments on commit dbf16e3

Please sign in to comment.