Uploaded image for project: 'RHEL Conversions'
  1. RHEL Conversions
  2. RHELC-1160

Race condition when deleting a temporary directory

XMLWordPrintable

    • 1
    • False
    • Hide

      None

      Show
      None
    • False
    • 2023-R4
    • Testable

      The directory that we store gpg public keys in when checking package signature is subject to a race condition. We have tried to fix this before but it is still happening from time to time.  We need to work harder to workaround it and also not fail if we cannot.

      The error (which shows up from time to time in CI) looks like this:
      {{_______________ TestFindKeys.test_find_keyid_race_in_gpg_cleanup _______________
      [..]
      finally:
      try:

      1. Remove the temporary keyring. We can't use the context manager
      2. for this because it isn't available on Python-2.7 (RHEL7)
        > shutil.rmtree(temporary_dir)

      convert2rhel/utils.py:872:
      _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

      self = <convert2rhel.unit_tests.utils_test.TestFindKeys.MockedRmtree object at 0x7f068529ee10>
      args = ('/tmp/tmpu_e6f2nb',), kwargs = {}

      def _call_(self, *args, **kwargs):

      1. Fail on the first call
        self.called += 1
        if self.called == 1:
        > raise self.exception
        E FileNotFoundError: [Errno 2] File not found

      convert2rhel/unit_tests/utils_test.py:278: FileNotFoundError

      During handling of the above exception, another exception occurred:

      self = <convert2rhel.unit_tests.utils_test.TestFindKeys object at 0x7f0685f9b828>
      monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f068529ee48>

      def test_find_keyid_race_in_gpg_cleanup(self, monkeypatch):
      real_rmtree = shutil.rmtree
      monkeypatch.setattr(shutil, "rmtree", self.MockedRmtree(OSError(2, "File not found"), real_rmtree))

      > assert utils.find_keyid(self.gpg_key) == "fd431d51"

      convert2rhel/unit_tests/utils_test.py:293:
      _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
      convert2rhel/utils.py:881: in find_keyid
      shutil.rmtree(temporary_dir)
      convert2rhel/unit_tests/utils_test.py:280: in _call_
      return self.real_rmtree(*args, **kwargs)
      /usr/lib64/python3.6/shutil.py:486: in rmtree
      _rmtree_safe_fd(fd, path, onerror)
      /usr/lib64/python3.6/shutil.py:444: in _rmtree_safe_fd
      onerror(os.unlink, fullname, sys.exc_info())
      _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
      [..]
      else:
      try:
      > os.unlink(name, dir_fd=topfd)
      E FileNotFoundError: [Errno 2] No such file or directory: 'S.gpg-agent.browser'

      /usr/lib64/python3.6/shutil.py:442: FileNotFoundError}}
      Acceptance Criteria:

      • We can try more times to delete the file.
      • If we have tried several times and continue to fail, emit a warning for the user so they can delete it manually if they want to.
      • Do not fail in this case.  The temporary file is a socket file for talking to a gpg-agent which has stopped (hence, why gpg has removed it before we were able to).

            tkuratom@redhat.com Toshio Kuratomi
            tkuratom@redhat.com Toshio Kuratomi
            Rodolfo Olivieri
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: