Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout environment variable, fix make test examples in CONTRIBUTION.md #110

Closed
wants to merge 11 commits into from

Conversation

ways
Copy link

@ways ways commented Aug 12, 2024

Closes #109

@ways
Copy link
Author

ways commented Aug 12, 2024

The result can be tested like this:

> cat Dockerfile.larsfp 
# build:
#  docker build --tag copernicusmarine/copernicusmarine:larsfp --tag copernicusmarine/copernicusmarine:latest -f Dockerfile.larsfp .
# test run:
#  docker run -it --rm --entrypoint bash docker.io/copernicusmarine/copernicusmarine:latest

FROM python:slim

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1

# Install and setup poetry
RUN apt-get update && apt install -y curl

RUN curl -sSL curl -sSL https://install.python-poetry.org | python3 -
ENV PATH="${PATH}:/root/.local/bin"

WORKDIR /app
COPY . .
RUN poetry config virtualenvs.create false \
  && poetry install --no-interaction --no-ansi

ENTRYPOINT [ "/bin/bash" ]

docker build --tag copernicusmarine/copernicusmarine:larsfp -f Dockerfile.larsfp .

Run with default timeout:

docker run -it --rm --entrypoint bash docker.io/copernicusmarine/copernicusmarine:larsfp
root@44ac7deaf232:/app# time copernicusmarine describe
...
real	0m13.452s
user	0m7.143s
sys	0m1.562s
root@44ac7deaf232:/app# 

Run with 2 second timeout:

> docker run -it --rm --entrypoint bash docker.io/copernicusmarine/copernicusmarine:larsfp
root@d1cfb35b7399:/app# COPERNICUSMARINE_GET_TIMEOUT=2 copernicusmarine describe
Fetching catalog:   0%|                                                           | 0/3 [00:00<?, ?it/s]Debug: Setting timeout 2s
ERROR - 2024-08-12T09:54:20Z - Unexpected error while downloading: '>' not supported between instances of 'str' and 'int'
ERROR - 2024-08-12T09:54:20Z - Type error: '>' not supported between instances of 'str' and 'int'
Fetching catalog:   0%|                                                           | 0/3 [00:00<?, ?it/s]
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7bc355b90da0>

@@ -70,5 +73,6 @@ def _get_client_required_versions(
url_mds_versions,
params=construct_query_params_for_marine_data_store_monitoring(),
proxies=session.proxies,
timeout=COPERNICUSMARINE_GET_TIMEOUT,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather have it in the copernicusmarine/core_functions/sessions.py when the session is initialised so that if the request is reused somewhere it has the same timeout

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that was impossible, but there seems to be a way, https://stackoverflow.com/questions/41295142/is-there-a-way-to-globally-override-requests-timeout-setting Will add.

Copy link
Author

@ways ways Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the retries set at session level are causing problems.

get_configured_requests_session sets Retry(total=5, backoff_factor=1 causing these times:

root@08ad85780a2a:/app# export COPERNICUSMARINE_CONNECTION_TIMEOUT=1
root@08ad85780a2a:/app# time copernicusmarine describe
real	0m38.225s
root@08ad85780a2a:/app# export COPERNICUSMARINE_CONNECTION_TIMEOUT=3
root@08ad85780a2a:/app# time copernicusmarine describe
real	0m50.229s

So when the connections time out, it will retry with longer and longer sleeps, thus using much more than my intention.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but it makes sense though as the retry should be triggered for a connection timeout 🤔 at least it's not hanging for ever

@ways
Copy link
Author

ways commented Aug 20, 2024

Pushing a new version, but haven't tested yet. Will do before the day is over.

@renaudjester
Copy link
Collaborator

Closing this as it will be released for v2 and has been done here: #146

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing timeout
2 participants