Ticket #2964: 0001-Race-condition-while-buddy-initiation-2964.patch

File 0001-Race-condition-while-buddy-initiation-2964.patch, 4.0 KB (added by alsroot, 13 years ago)
  • src/jarabe/model/neighborhood.py

    From 7a6abfc4542e288833b2f9fcb9032cd6366383e8 Mon Sep 17 00:00:00 2001
    From: Aleksey Lim <alsroot@activitycentral.org>
    Date: Thu, 14 Jul 2011 03:10:59 +0000
    Subject: [PATCH sugar] Race condition while buddy initiation #2964
    
    ---
     src/jarabe/model/neighborhood.py |   55 +++++++++++++++++++------------------
     1 files changed, 28 insertions(+), 27 deletions(-)
    
    diff --git a/src/jarabe/model/neighborhood.py b/src/jarabe/model/neighborhood.py
    index 5a4c5a5..f27e2be 100644
    a b class _Account(gobject.GObject): 
    545545        logging.debug('_Account.__got_buddy_info_cb %r', handle)
    546546        self.emit('buddy-updated', self._buddy_handles[handle], properties)
    547547
     548    def _call_buddy(self, meth, handle, cb, args, tries, timeout=1):
     549        """Workaround for http://bugs.sugarlabs.org/ticket/2964"""
     550
     551        if CONNECTION_INTERFACE_BUDDY_INFO not in self._connection:
     552            return
     553
     554        def error_handler(error):
     555            if tries <= 1:
     556                raise RuntimeError('No luck with %s: %s' % (meth, error))
     557            logging.debug('Try to call %r in %d seconds', meth, timeout)
     558            gobject.timeout_add_seconds(timeout, self._call_buddy,
     559                    meth, handle, cb, args, tries - 1, timeout * 2)
     560
     561        connection = self._connection[CONNECTION_INTERFACE_BUDDY_INFO]
     562        connection_meth = eval('connection.%s' % meth)
     563        connection_meth(handle, reply_handler=partial(cb, *args),
     564                error_handler=error_handler, byte_arrays=True,
     565                timeout=_QUERY_DBUS_TIMEOUT)
     566
    548567    def __get_contact_attributes_cb(self, attributes):
    549568        logging.debug('_Account.__get_contact_attributes_cb %r',
    550569                      attributes.keys())
    class _Account(gobject.GObject): 
    571590                self._buddy_handles[handle] = contact_id
    572591
    573592                if CONNECTION_INTERFACE_BUDDY_INFO in self._connection:
    574                     connection = \
    575                             self._connection[CONNECTION_INTERFACE_BUDDY_INFO]
    576 
    577                     connection.GetProperties(
    578                         handle,
    579                         reply_handler=partial(self.__got_buddy_info_cb, handle,
    580                                               nick),
    581                         error_handler=partial(self.__error_handler_cb,
    582                                               'BuddyInfo.GetProperties'),
    583                         byte_arrays=True,
    584                         timeout=_QUERY_DBUS_TIMEOUT)
    585 
    586                     connection.GetActivities(
    587                         handle,
    588                         reply_handler=partial(self.__got_activities_cb,
    589                                               handle),
    590                         error_handler=partial(self.__error_handler_cb,
    591                                               'BuddyInfo.GetActivities'),
    592                         timeout=_QUERY_DBUS_TIMEOUT)
    593 
    594                     connection.GetCurrentActivity(
    595                         handle,
    596                         reply_handler=partial(self.__get_current_activity_cb,
    597                                               handle),
    598                         error_handler=partial(self.__error_handler_cb,
    599                                               'BuddyInfo.GetCurrentActivity'),
    600                         timeout=_QUERY_DBUS_TIMEOUT)
     593                    # Without GetProperties, newly appeared buddy
     594                    # won't be shown, so try 5 times
     595                    self._call_buddy('GetProperties', handle,
     596                            self.__got_buddy_info_cb, [handle, nick], 5)
     597                    # The rest of data might be not set via pep on the server
     598                    self._call_buddy('GetActivities', handle,
     599                            self.__got_activities_cb, [handle], 1)
     600                    self._call_buddy('GetCurrentActivity', handle,
     601                            self.__get_current_activity_cb, [handle], 1)
    601602
    602603                self.emit('buddy-added', contact_id, nick, handle)
    603604