From 8376286e7e20dd5c5a595d4d6eb87bc401fb51f3 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sun, 3 Aug 2014 11:43:28 +0200 Subject: [PATCH] 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 80f5c9158d485099fac9693d7fbad74a29578a09) --- mopidy/zeroconf.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mopidy/zeroconf.py b/mopidy/zeroconf.py index 0f991ba3..9f726957 100644 --- a/mopidy/zeroconf.py +++ b/mopidy/zeroconf.py @@ -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)