liormizr / s3path

s3path is a pathlib extension for AWS S3 Service
Apache License 2.0
208 stars 40 forks source link

IndexError: pop from an empty deque when using glob in production #119

Closed Blacksuan19 closed 1 year ago

Blacksuan19 commented 1 year ago

Environment

enviroment: AWS ECS python version: 3.10.9 (python:3.10-buster docker image) package version: 0.4.1

Error Details

S3Path.glob(key) randomly fails with IndexError: pop from an empty deque even after confirming that key path is not an empty folder. Testing locally with the same python version on paths with no files returns an empty list (so the error isn't because the path is empty), when testing with non empty paths it works correctly returning a list of S3Path objects.

Error Stacktrace

  File "/usr/local/lib/python3.10/site-packages/s3path.py", line 905, in glob
    yield from self._glob(pattern)
  File "/usr/local/lib/python3.10/site-packages/s3path.py", line 920, in _glob
    yield from selector.select()
  File "/usr/local/lib/python3.10/site-packages/s3path.py", line 632, in select
    for target in self._deep_cached_dir_scan():
  File "/usr/local/lib/python3.10/site-packages/s3path.py", line 694, in _deep_cached_dir_scan
    cache.add(target_path_parts, target_path)
  File "/usr/local/lib/python3.10/site-packages/s3path.py", line 718, in add
    self._queue.pop()
IndexError: pop from an empty deque

Source code

the error occurs with two different codes in 2 different places, the first occurrence is inside a config package using S3Path and is random since the package is used in every run but the error doesn't always occur.

First occurrence

models = list(client_models.glob(f"*{self.target_column}*.pkl"))

Second occurance

the error is not from list.pop() on an empty list because then it will be IndexError: pop from empty list and not the above error.

report_file = list(
    S3Path.from_uri(
        f"s3://{conf.target_bucket}/{conf.report_prefix}/{conf.client}"
    ).glob("*.html")
).pop()

let me know if you need any other information.

Blacksuan19 commented 1 year ago

just noticed the error was fixed 3 days ago here. I will close this issue now.