Skip to content

temp_sys_path removes by index and drops the wrong entry if sys.path is modified while a check is loaded #3753

Todo

Description

@casparvl

I hit a strange issue when one of our checks tried to use EasyBuild as a library to resolve a toolchain hierarchy. I suddenly got:

ERROR: run session stopped: key error: 'GCC'
ERROR: KeyError: 'GCC'

When running the same commands interactively, I saw no issues. The root cause turns out to be a modification to the sys.path made by reframe: easybuild searches the sys.path to located the toolchains, and the modification caused this to not be found.

Fundamentally, the issue is this:

reframe.utility.temp_sys_path appends a path on enter and removes it on exit by index:

  def __enter__(self):
      self._pos = len(sys.path)
      sys.path.append(self._path)

  def __exit__(self, ...):
      sys.path.pop(self._pos)

The pop happens by position. This means that if anything that is run with temp_sys_path modifies the sys.path itself, the wrong thing gets popped by reframe. That happened here: EasyBuild inserts a temporary face_vsc at sys.path[0], and the site-packages dir that contained the toolchains for EasyBuild got popped by reframe upon __exit__. The path that reframe 'temporarily' entered in the __enter__ block was actually left behind.

I realize this type of usage is a bit exotic. On the other hand there are two relatively easy fixes to make this more robust:

  1. Pop by value
  2. Store and restore a sys.path checkpoint

The second solution is the most robust, as it would even undo changes to the sys.path that may have been made by tests.

Note that we have a workaround in place (calling search_toolchain('') right after the EasyBuild import, before temp_sys_path modified the sys.path), so it's not super urgent to fix this - but I guess this could be made more robust before the next person hits it. These errors are rather hard to debug :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions