Skip to content

Commit

Permalink
stop control thread before closing sockets on it (#659)
Browse files Browse the repository at this point in the history
closing sockets in-use by another thread is a recipe for SIGABRT

skip `close(all_fds=True)` in favor of explicit cleanup of sockets
  • Loading branch information
minrk authored May 7, 2021
1 parent c772130 commit 31ec597
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 12 additions & 3 deletions ipykernel/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ def __init__(self, **kwargs):
self.pydev_do_not_trace = True
self.is_pydev_daemon_thread = True

def run(self):
def run(self):
self.io_loop.make_current()
self.io_loop.start()
self.io_loop.close(all_fds=True)
try:
self.io_loop.start()
finally:
self.io_loop.close()

def stop(self):
"""Stop the thread.
This method is threadsafe.
"""
self.io_loop.add_callback(self.io_loop.stop)
6 changes: 5 additions & 1 deletion ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ def close(self):
self.log.debug("Closing iopub channel")
self.iopub_thread.stop()
self.iopub_thread.close()
if self.control_thread and self.control_thread.is_alive():
self.log.debug("Closing control thread")
self.control_thread.stop()
self.control_thread.join()

if self.debugpy_socket and not self.debugpy_socket.closed:
self.debugpy_socket.close()
Expand Down Expand Up @@ -487,7 +491,7 @@ def init_kernel(self):
control_stream=control_stream,
debugpy_stream=debugpy_stream,
debug_shell_socket=self.debug_shell_socket,
shell_stream=shell_stream,
shell_stream=shell_stream,
control_thread=self.control_thread,
iopub_thread=self.iopub_thread,
iopub_socket=self.iopub_socket,
Expand Down

0 comments on commit 31ec597

Please sign in to comment.