Merge ~r00ta/maas:lp-2029522-3.5 into maas:3.5

Proposed by Jacopo Rota
Status: Merged
Approved by: Jacopo Rota
Approved revision: 86672b32550c152ba6cafe6fe5d6c56176a3f30d
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~r00ta/maas:lp-2029522-3.5
Merge into: maas:3.5
Diff against target: 45 lines (+14/-2)
2 files modified
src/provisioningserver/rpc/connectionpool.py (+2/-1)
src/provisioningserver/rpc/tests/test_connectionpool.py (+12/-1)
Reviewer Review Type Date Requested Status
Jacopo Rota Approve
MAAS Lander unittests Pending
Review via email: mp+463622@code.launchpad.net

Commit message

fix: lp-2029522. Check if the connection was already dropped in the connectionpool disconnect method.

To post a comment you must log in.
Revision history for this message
Jacopo Rota (r00ta) wrote :

self approving backport

review: Approve

Update scan failed

At least one of the branches involved have failed to scan. You can manually schedule a rescan if required.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/provisioningserver/rpc/connectionpool.py b/src/provisioningserver/rpc/connectionpool.py
2index 55b00cb..6dacb9f 100644
3--- a/src/provisioningserver/rpc/connectionpool.py
4+++ b/src/provisioningserver/rpc/connectionpool.py
5@@ -135,7 +135,8 @@ class ConnectionPool:
6 return conn
7
8 def disconnect(self, connection):
9- return connection.transport.loseConnection()
10+ if connection.transport:
11+ return connection.transport.loseConnection()
12
13 @inlineCallbacks
14 def add_connection(self, eventloop, connection):
15diff --git a/src/provisioningserver/rpc/tests/test_connectionpool.py b/src/provisioningserver/rpc/tests/test_connectionpool.py
16index 9506130..bf2ed4e 100644
17--- a/src/provisioningserver/rpc/tests/test_connectionpool.py
18+++ b/src/provisioningserver/rpc/tests/test_connectionpool.py
19@@ -1,7 +1,7 @@
20 # Copyright 2022 Canonical Ltd. This software is licensed under the
21 # GNU Affero General Public License version 3 (see the file LICENSE).
22
23-from unittest.mock import Mock
24+from unittest.mock import Mock, PropertyMock
25
26 from twisted.internet.defer import inlineCallbacks, succeed
27 from twisted.internet.endpoints import TCP6ClientEndpoint
28@@ -318,6 +318,17 @@ class TestConnectionPool(MAASTestCase):
29 cp.disconnect(connection)
30 connection.transport.loseConnection.assert_called_once_with()
31
32+ def test_drop_connection_if_connection_already_dropped(self):
33+ connection = Mock()
34+ type(connection).transport = PropertyMock(return_value=None)
35+ cp = ConnectionPool(Clock(), Mock())
36+ try:
37+ cp.disconnect(connection)
38+ except Exception:
39+ self.fail(
40+ "The connection was already dropped and the disconnect function raised an unexpected exception."
41+ )
42+
43 @inlineCallbacks
44 def test_add_connection_adds_the_staged_connection(self):
45 eventloop = Mock()

Subscribers

People subscribed via source and target branches