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

DockerContainer.log() times out after 300 seconds / 5 minutes of streaming #901

Open
sauladam opened this issue Sep 28, 2024 · 3 comments
Open

Comments

@sauladam
Copy link

Long story short

Streaming logs for a container works fine for exactly 5 minutes before the process times out. This seems to be an HTTP timeout, probably a default value in aiohttp.

  • Expected behaviour: Stream logs until container goes away.
  • Actual behaviour: Only streams for 5 minutes even though the container is still running.

How to reproduce

docker = Docker()
container = await docker.containers.get(container_id)
logs_stream = container.log(stdout=True, stderr=True, follow=True)

async for log in logs_stream:
    print(log)

Let it cook for 5 minutes.

Sidenote:

Subscribing to docker events works fine.

I also went sourcediving and found the logs property on the DockerContainer class which is a DockerLog instance.

I then tried to do the same as with docker events:

subscription = container.logs.subscribe()
asyncio.create_task(container.logs.run(timestamps=True))

while True:
    log = await subscription.get()

    if log is None:
        break
    print(log)

But this also times out after 5 minutes.

Your environment

Python 3.12.6 (inside Docker container from python:3.12-alpine3.19)
aiodocker==0.23.0
aiohttp==3.9.5 (clamped because of an issue with newer versions)

@toerb
Copy link

toerb commented Oct 7, 2024

The timeout in question is the sock_read timeout in aiohttp.
It can be set via the session parameter while instantiating a new docker client:

client = aiodocker.Docker(
    session=aiohttp.ClientSession(
        connector=aiohttp.UnixConnector('/var/run/docker.sock'),
        timeout=aiohttp.ClientTimeout(total=None, connect=30, sock_connect=30, sock_read=None)
    )
)

@sauladam
Copy link
Author

sauladam commented Oct 8, 2024

@toerb My guy just stepping in and dropping the solution like a chad!

12 hours in and the logs keep coming - thanks a ton! 🫶

This seems like a solid default for handling streaming logs with UnixConnectors. From what I can tell, the timeout can be adjusted per request, so setting it for the log requests makes sense. Would you mind if I opened a PR for this, giving you full credit for your solution?

@toerb
Copy link

toerb commented Oct 8, 2024

Would you mind if I opened a PR for this, giving you full credit for your solution?

No, not at all! I am happy my comment was of help ;)

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

No branches or pull requests

2 participants