alot icon indicating copy to clipboard operation
alot copied to clipboard

tests sometimes fail to remove S.gpg-agent.browser (race condition?)

Open josch opened this issue 5 years ago • 0 comments

Not a regression this time but indeed a problem that existed since 0.7 but which neither me nor the other Debian maintainer @jljusten was able to reproduce. So we don't know where exactly the problem comes from, but I was given ssh access to a machine where I was able to reproduce this error. I just cannot reproduce it on my own laptop. Another platform where the error consistently shows is the reproducible builds setup: https://people.debian.org/~sanvila/build-logs/alot/

The problem is, that on these platforms, the unit tests fail in the following way:

======================================================================
ERROR: tearDownModule (tests.commands.utils_tests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/tests/utilities.py", line 133, in wrapper
    self.do_cleanups()
  File "/<<PKGBUILDDIR>>/tests/utilities.py", line 121, in do_cleanups
    func(*args, **kwargs)
  File "/usr/lib/python3.7/shutil.py", line 491, in rmtree
    _rmtree_safe_fd(fd, path, onerror)
  File "/usr/lib/python3.7/shutil.py", line 449, in _rmtree_safe_fd
    onerror(os.unlink, fullname, sys.exc_info())
  File "/usr/lib/python3.7/shutil.py", line 447, in _rmtree_safe_fd
    os.unlink(entry.name, dir_fd=topfd)
FileNotFoundError: [Errno 2] No such file or directory: 'S.gpg-agent.browser'

======================================================================
ERROR: tearDownClass (tests.db.utils_test.TestMessageFromFile)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/tests/utilities.py", line 30, in _tear_down_class_wrapper
    original()
  File "/<<PKGBUILDDIR>>/tests/utilities.py", line 30, in _tear_down_class_wrapper
    original()
  File "/<<PKGBUILDDIR>>/tests/utilities.py", line 30, in _tear_down_class_wrapper
    original()
  [Previous line repeated 16 more times]
  File "/<<PKGBUILDDIR>>/tests/utilities.py", line 32, in _tear_down_class_wrapper
    cls.doClassCleanups()
  File "/<<PKGBUILDDIR>>/tests/utilities.py", line 102, in doClassCleanups
    func(*args, **kwargs)
  File "/usr/lib/python3.7/shutil.py", line 491, in rmtree
    _rmtree_safe_fd(fd, path, onerror)
  File "/usr/lib/python3.7/shutil.py", line 449, in _rmtree_safe_fd
    onerror(os.unlink, fullname, sys.exc_info())
  File "/usr/lib/python3.7/shutil.py", line 447, in _rmtree_safe_fd
    os.unlink(entry.name, dir_fd=topfd)
FileNotFoundError: [Errno 2] No such file or directory: 'S.gpg-agent.browser'

Here is the Debian bug with more infos https://bugs.debian.org/906335 but still nobody knows to reliably reproduce this problem on any machine. Santiago Vila discovered that the issue we see here might in fact be a race condition similar to here hpk42/muacrypt/issues/3 where the fix is to run shutil.rmtree with ignore_errors=True so that it will ignore a previously deleted S.gpg-agent.browser. And indeed, with this patch:

--- a/tests/commands/utils_tests.py
+++ b/tests/commands/utils_tests.py
@@ -48,7 +48,7 @@ MOD_CLEAN.add_cleanup(DEVNULL.close)
 @MOD_CLEAN.wrap_setup
 def setUpModule():
     home = tempfile.mkdtemp()
-    MOD_CLEAN.add_cleanup(shutil.rmtree, home)
+    MOD_CLEAN.add_cleanup(shutil.rmtree, home, ignore_errors=True)
     mock_home = mock.patch.dict(os.environ, {'GNUPGHOME': home})
     mock_home.start()
     MOD_CLEAN.add_cleanup(mock_home.stop)
--- a/tests/db/utils_test.py
+++ b/tests/db/utils_test.py
@@ -353,7 +353,7 @@ class TestMessageFromFile(TestCaseClassC
     @classmethod
     def setUpClass(cls):
         home = tempfile.mkdtemp()
-        cls.addClassCleanup(shutil.rmtree, home)
+        cls.addClassCleanup(shutil.rmtree, home, ignore_errors=True)
         mock_home = mock.patch.dict(os.environ, {'GNUPGHOME': home})
         mock_home.start()
         cls.addClassCleanup(mock_home.stop)

everything seems to work fine on the affected machines.

Could you apply it or do you see a better way to solve this issue?

josch avatar Feb 12 '19 05:02 josch