Skip to content

Commit

Permalink
Make sure the Conn object only calls the notifyDisconnect callbacks
Browse files Browse the repository at this point in the history
once, by replacing the current subscription object with a new one
after delivering the notifications. A second call could mess up the
newer connection's state. (#4678)
  • Loading branch information
YngveNPettersen committed Apr 13, 2024
1 parent e05a2ca commit f9ffe15
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions master/buildbot/test/unit/worker/test_protocols_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,14 @@ def test_notify(self):
self.assertEqual(cb.call_args_list, [])
self.conn.notifyDisconnected()
self.assertNotEqual(cb.call_args_list, [])

def test_notify_twice(self):
cb = mock.Mock()

self.conn.notifyOnDisconnect(cb)
self.assertEqual(cb.call_args_list, [])
self.conn.notifyDisconnected()
self.assertNotEqual(cb.call_args_list, [])
cb.call_args_list = []
self.conn.notifyDisconnected()
self.assertEqual(cb.call_args_list, [])
3 changes: 3 additions & 0 deletions master/buildbot/worker/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ def newConnection(self, conn, workerName):
self.connections[workerName] = conn

def remove():
assert (
self.connections.get(workerName, None) == conn
), f"Attempt to remove non-connection entry for {workerName}"
del self.connections[workerName]

conn.notifyOnDisconnect(remove)
Expand Down
2 changes: 2 additions & 0 deletions master/buildbot/worker/protocols/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def notifyOnDisconnect(self, cb):

def notifyDisconnected(self):
self._disconnectSubs.deliver()
# Ensure that the disconnect notifications are not called twice
self._disconnectSubs = subscription.SubscriptionPoint(self._disconnectSubs.name)

def loseConnection(self):
raise NotImplementedError
Expand Down

0 comments on commit f9ffe15

Please sign in to comment.