Commit 6e7e58b4 authored by Guido Trotter's avatar Guido Trotter
Browse files

AsyncUDPSocket: fix IgnoreSignals usage and test

This bug was found in the asyncore master patch series, but actually
applies to 2.1 for AsyncUDPSocket as well.
Signed-off-by: default avatarGuido Trotter <>
Reviewed-by: default avatarMichael Hanselmann <>
parent 547a63b7
......@@ -112,10 +112,12 @@ class AsyncUDPSocket(GanetiBaseAsyncoreDispatcher):
# this method is overriding an asyncore.dispatcher method
def handle_read(self):
payload, address = utils.IgnoreSignals(self.recvfrom,
ip, port = address
self.handle_datagram(payload, ip, port)
recv_result = utils.IgnoreSignals(self.recvfrom,
if recv_result is not None:
payload, address = recv_result
ip, port = address
self.handle_datagram(payload, ip, port)
def handle_datagram(self, payload, ip, port):
"""Handle an already read udp datagram
......@@ -28,6 +28,7 @@ import socket
import time
from ganeti import daemon
from ganeti import utils
import testutils
......@@ -170,10 +171,14 @@ class TestAsyncUDPSocket(testutils.GanetiTestCase):
self.client = _MyAsyncUDPSocket()
self.server.bind(("", 0))
self.port = self.server.getsockname()[1]
# Save utils.IgnoreSignals so we can do evil things to it...
self.saved_utils_ignoresignals = utils.IgnoreSignals
def tearDown(self):
# ...and restore it as well
utils.IgnoreSignals = self.saved_utils_ignoresignals
def testNoDoubleBind(self):
......@@ -219,6 +224,17 @@ class TestAsyncUDPSocket(testutils.GanetiTestCase):
["p1", "p2", "error", "p3", "error", "terminate"])
self.assertEquals(self.server.error_count, 2)
def testSignaledWhileReceiving(self):
utils.IgnoreSignals = lambda fn, *args, **kwargs: None
self.client.enqueue_send("", self.port, "p1")
self.client.enqueue_send("", self.port, "p2")
self.assertEquals(self.server.received, [])
self.client.enqueue_send("", self.port, "terminate")
utils.IgnoreSignals = self.saved_utils_ignoresignals
self.assertEquals(self.server.received, ["p1", "p2", "terminate"])
if __name__ == "__main__":
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment