ovh / the-bastion-ansible-wrapper

Using Ansible through The Bastion
https://ovh.github.io/the-bastion/
Apache License 2.0
33 stars 12 forks source link

Race condition on the inventory cache file #10

Closed jouir closed 1 year ago

jouir commented 2 years ago

Hello,

Since the inventory cache feature, we have notice the following error:

Traceback (most recent call last):
  File "./extra/bastion/sshwrapper.py", line 96, in <module>
    main()
  File "./extra/bastion/sshwrapper.py", line 44, in main
    hostvar = get_hostvars(host)  # dict
  File "/tmp/bwrap_247825_so1sw9v8/awx_247825_ibg2laaa/project/extra/bastion/lib.py", line 113, in get_hostvars
    inventory = get_inventory()
  File "/tmp/bwrap_247825_so1sw9v8/awx_247825_ibg2laaa/project/extra/bastion/lib.py", line 45, in get_inventory
    cache_timeout=int(os.environ.get("BASTION_ANSIBLE_INV_CACHE_TIMEOUT", 60)),
  File "/tmp/bwrap_247825_so1sw9v8/awx_247825_ibg2laaa/project/extra/bastion/lib.py", line 88, in get_inventory_from_cache
    cache = json.load(fd)
  File "/usr/lib64/python3.6/json/__init__.py", line 299, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "/usr/lib64/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python3.6/json/decoder.py", line 355, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 1614071 (char 1614070)

When multiple jobs are running at the same time, we suspect a race condition when writing and reading on the inventory cache file.

jouir commented 1 year ago

Fixed by #13