isislovecruft / python-gnupg

A modified version of python-gnupg, including security patches, extensive documentation, and extra features.
Other
424 stars 172 forks source link

_trustdb Background thread timing issue #197

Closed dlowry closed 7 years ago

dlowry commented 7 years ago

The threaded call in fix_trustdb does not finish until nosetests is well into the tearDown call of unit tests. The tearDown() is removing temporary directories created for the unittest but the threaded call in fix_trustdb is still creating files. Our nosetest failure rate is approximately 50%.

Below, please find the patch, in the form of a diff, we have implemented to address the issue:

--- gnupg-2.3.0-orig/gnupg/_trust.py    2016-12-20 23:01:22.000000000 -0600
+++ gnupg-2.3.0/gnupg/_trust.py 2017-06-23 09:16:31.255334692 -0500
@@ -60,6 +60,7 @@
     export_proc = cls._open_subprocess(['--export-ownertrust'])
     tdb = open(trustdb, 'wb')
     _util._threaded_copy_data(export_proc.stdout, tdb)
+    export_proc.wait()

 def import_ownertrust(cls, trustdb=None):
     """Import ownertrust from a trustdb file.
@@ -79,6 +80,7 @@
         log.error("trustdb file %s does not exist!" % trustdb)

     _util._threaded_copy_data(tdb, import_proc.stdin)
+    import_proc.wait()

 def fix_trustdb(cls, trustdb=None):
     """Attempt to repair a broken trustdb.gpg file.
@@ -106,3 +108,5 @@
     export_proc = cls._open_subprocess(['--export-ownertrust'])
     import_proc = cls._open_subprocess(['--import-ownertrust'])
     _util._threaded_copy_data(export_proc.stdout, import_proc.stdin)
+    export_proc.wait()
+    import_proc.wait()
isislovecruft commented 7 years ago

Hi @dlowry! Thanks for bug report and extra thank you for the patch. I've applied this in commit 5d47c3b5eb00 and merged it into develop for the next version (2.3.2).