zeroconf: Fix intermittent dbus/avahi exception

This fixes an issue where I sometimes would get an error from dbus
'Unable to guess signature from an empty list'. After some digging
and checking the avahi dbus specs I found they expect the text list
to have a signature of 'aay' (an array of arrays containing bytes).
So instead of using python lists we now use a 'typed' dbus array.

It is not clear to me why this is a heisenbug, but this fix does
seem to make it go away.

(cherry picked from commit 80f5c9158d)
This commit is contained in:
Thomas Adamcik 2014-08-03 11:43:28 +02:00 committed by Stein Magnus Jodal
parent 3a442483eb
commit 8376286e7e

View File

@ -23,8 +23,11 @@ def _is_loopback_address(host):
host == '::1')
def _convert_text_to_dbus_bytes(text):
return [dbus.Byte(ord(c)) for c in text]
def _convert_text_list_to_dbus_format(text_list):
array = dbus.Array(signature='ay')
for text in text_list:
array.append([dbus.Byte(ord(c)) for c in text])
return array
class Zeroconf(object):
@ -91,11 +94,11 @@ class Zeroconf(object):
'org.freedesktop.Avahi', server.EntryGroupNew()),
'org.freedesktop.Avahi.EntryGroup')
text = [_convert_text_to_dbus_bytes(t) for t in self.text]
self.group.AddService(
_AVAHI_IF_UNSPEC, _AVAHI_PROTO_UNSPEC,
dbus.UInt32(_AVAHI_PUBLISHFLAGS_NONE), self.name, self.stype,
self.domain, self.host, dbus.UInt16(self.port), text)
self.domain, self.host, dbus.UInt16(self.port),
_convert_text_list_to_dbus_format(self.text))
self.group.Commit()
logger.debug('%s: Published', self)