Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions slack_sdk/socket_mode/builtin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ def close(self):
self.closed = True
self.auto_reconnect_enabled = False
self.disconnect()
if self.current_session_runner.is_alive():
self.current_session_runner.shutdown()
if self.current_app_monitor.is_alive():
self.current_app_monitor.shutdown()
if self.message_processor.is_alive():
Expand Down
18 changes: 18 additions & 0 deletions tests/slack_sdk/socket_mode/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ def test_init_close(self):
finally:
client.close()

def test_close_shuts_down_all_runners(self):
# Regression for #1873: close() must shut down current_session_runner
# along with current_app_monitor and message_processor. Previously
# current_session_runner was left running (100 ms loop), so each
# init/close cycle leaked one thread.
client = SocketModeClient(app_token="xapp-A111-222-xyz")
# The first two runners are started inside __init__.
self.assertTrue(client.current_session_runner.is_alive())
self.assertTrue(client.message_processor.is_alive())
client.close()
# IntervalRunner.shutdown() joins the thread, so by the time
# close() returns these are no longer alive.
self.assertFalse(client.current_session_runner.is_alive())
self.assertFalse(client.message_processor.is_alive())
# current_app_monitor is only started in connect(); since this test
# never connects, it should report not-alive both before and after.
self.assertFalse(client.current_app_monitor.is_alive())

def test_issue_new_wss_url(self):
client = SocketModeClient(
app_token="xapp-A111-222-xyz",
Expand Down
Loading