From be5ef66a3a9b0f3f1369d6181ac22e95c96f3c9e Mon Sep 17 00:00:00 2001 From: "Daniel A. Wozniak" Date: Thu, 2 Nov 2023 15:11:39 -0700 Subject: [PATCH] Connect callback closes it's request channel --- changelog/65464.fixed.md | 1 + salt/channel/client.py | 2 +- .../pytests/functional/channel/test_client.py | 23 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 changelog/65464.fixed.md create mode 100644 tests/pytests/functional/channel/test_client.py diff --git a/changelog/65464.fixed.md b/changelog/65464.fixed.md new file mode 100644 index 00000000000..a931b6a6445 --- /dev/null +++ b/changelog/65464.fixed.md @@ -0,0 +1 @@ +Publish channel connect callback method properly closes it's request channel. diff --git a/salt/channel/client.py b/salt/channel/client.py index 5d07a04ad63..88fbad3ff0b 100644 --- a/salt/channel/client.py +++ b/salt/channel/client.py @@ -564,7 +564,7 @@ class AsyncPubChannel: log.info("fire_master failed", exc_info=True) finally: # SyncWrapper will call either close() or destroy(), whichever is available - del req_channel + req_channel.close() else: self._reconnected = True except Exception as exc: # pylint: disable=broad-except diff --git a/tests/pytests/functional/channel/test_client.py b/tests/pytests/functional/channel/test_client.py new file mode 100644 index 00000000000..43a9dea0c81 --- /dev/null +++ b/tests/pytests/functional/channel/test_client.py @@ -0,0 +1,23 @@ +import salt.channel.client +from tests.support.mock import MagicMock, patch + + +async def test_async_pub_channel_connect_cb(minion_opts): + """ + Validate connect_callback closes the request channel it creates. + """ + minion_opts["master_uri"] = "tcp://127.0.0.1:4506" + minion_opts["master_ip"] = "127.0.0.1" + channel = salt.channel.client.AsyncPubChannel.factory(minion_opts) + + async def send_id(*args): + return + + channel.send_id = send_id + channel._reconnected = True + + mock = MagicMock(salt.channel.client.AsyncReqChannel) + with patch("salt.channel.client.AsyncReqChannel.factory", return_value=mock): + await channel.connect_callback(None) + mock.send.assert_called_once() + mock.close.assert_called_once()