0

I have a Flask backend running inside Docker, and it streams AI responses using a generator.
Locally it works perfectly, but after deploying with Nginx + Docker Compose, the streamed response gets cut off halfway.

Nginx config:

proxy_buffering off;
proxy_cache off;

proxy_read_timeout 300s;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;

proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header X-Accel-Buffering no;

default

Flask endpoint:

return Response(
    ai_sdk_stream_generator(),
    mimetype='text/plain',
    headers={'X-Accel-Buffering': 'no', 'Connection': 'keep-alive'}
)

main

Issue:
Inside Docker, Nginx randomly stops sending chunks to the client. Flask continues printing chunks in logs, but the browser stops receiving them. No timeout logs or errors.

Tried:

  • disabling buffering

  • increasing timeouts

  • chunked transfer

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.