bintree: add timeout for closing binhost conn v2.1.9.27
authorZac Medico <zmedico@gentoo.org>
Fri, 31 Dec 2010 08:51:24 +0000 (00:51 -0800)
committerZac Medico <zmedico@gentoo.org>
Fri, 31 Dec 2010 09:01:59 +0000 (01:01 -0800)
Hopefully this solves bug #350139.

pym/portage/dbapi/bintree.py

index 46f6509a7545cc777a9c39585b347fda3b0c0338..55118a28552c3ed1656fec26652598c88647c71b 100644 (file)
@@ -23,7 +23,7 @@ from portage.cache.mappings import slot_dict_class
 from portage.const import CACHE_PATH
 from portage.dbapi.virtual import fakedbapi
 from portage.dep import Atom, use_reduce, paren_enclose
-from portage.exception import InvalidPackageName, \
+from portage.exception import AlarmSignal, InvalidPackageName, \
        PermissionDenied, PortageException
 from portage.localization import _
 from portage import _movefile
@@ -806,7 +806,18 @@ class binarytree(object):
                                                        rmt_idx.readBody(f_dec)
                                                        pkgindex = rmt_idx
                                finally:
-                                       f.close()
+                                       # Timeout after 5 seconds, in case close() blocks
+                                       # indefinitely (see bug #350139).
+                                       try:
+                                               try:
+                                                       AlarmSignal.register(5)
+                                                       f.close()
+                                               finally:
+                                                       AlarmSignal.unregister()
+                                       except AlarmSignal:
+                                               writemsg("\n\n!!! %s\n" % \
+                                                       _("Timed out while closing connection to binhost"),
+                                                       noiselevel=-1)
                        except EnvironmentError as e:
                                writemsg(_("\n\n!!! Error fetching binhost package" \
                                        " info from '%s'\n") % base_url)