Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify connection disconnect during error handling of new connection … #7463

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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, [])
5 changes: 5 additions & 0 deletions master/buildbot/worker/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def newConnection(self, conn, workerName):
raise RuntimeError("rejecting duplicate worker")
except defer.CancelledError:
old_conn.loseConnection()
old_conn.notifyDisconnected()
log.msg(
f"Connected worker '{workerName}' ping timed out after {self.PING_TIMEOUT} "
"seconds"
Expand All @@ -140,6 +141,7 @@ def newConnection(self, conn, workerName):
raise
except Exception as e:
old_conn.loseConnection()
old_conn.notifyDisconnected()
log.msg(f"Got error while trying to ping connected worker {workerName}:{e}")
log.msg(f"Old connection for '{workerName}' was lost, accepting new")

Expand All @@ -155,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
7 changes: 7 additions & 0 deletions master/buildbot/worker/protocols/pb.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from buildbot.pbutil import decode
from buildbot.util import deferwaiter
from buildbot.worker import AbstractWorker
from buildbot.worker.protocols import base


Expand Down Expand Up @@ -146,6 +147,12 @@ def loseConnection(self):
# keepalive handling

def _do_keepalive(self):
if not self.worker or (
isinstance(self.worker, AbstractWorker) and self.worker.isConnected() != self
):
self.loseConnection()
self.notifyDisconnected()
return defer.fail(None)
return self.mind.callRemote('print', message="keepalive")

def stopKeepaliveTimer(self):
Expand Down
3 changes: 3 additions & 0 deletions newsfragments/really-disconnect-unattached-connections.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Notify disconnect of connections that are being unattached when a replacement connection is being set up.
Additionally, make sure the notification callbacks cannot be called twice, and that a disconnected connection
cannot send a KeepAlive.