Changes between Initial Version and Version 1 of Ticket #29800, comment 15


Ignore:
Timestamp:
Sep 8, 2023, 11:28:20 AM (16 months ago)
Author:
Aditya Dhara

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #29800, comment 15

    initial v1  
    1 Hi folks, I encountered a similar bug and since this thread was the only place I could see information on this bug I thought I'll share what I found after working around this issue
     1Hi folks, I encountered a similar bug and since this thread was the only place I could see information on this bug I thought I'll share what I found
    22
    33TL;DR I think this is because of the way gunicorn uses the content-length header [here](https://github.com/benoitc/gunicorn/blob/ab9c8301cb9ae573ba597154ddeea16f0326fc15/gunicorn/http/body.py#L128-L129)
     
    77Gunicorn chooses different "readers" based on whether a `content-length` header is set, the `transfer-encoding` header has value `chunked`, or neither: https://github.com/benoitc/gunicorn/blob/ab9c8301cb9ae573ba597154ddeea16f0326fc15/gunicorn/http/message.py#L125-L154
    88
    9 if content-length is set, it uses a `LengthReader` is used, which loops infinitely until a certain length is reached: https://github.com/benoitc/gunicorn/blob/ab9c8301cb9ae573ba597154ddeea16f0326fc15/gunicorn/http/body.py#L126-L130
     9if content-length is set, it uses a `LengthReader`, which loops infinitely until a certain length is reached: https://github.com/benoitc/gunicorn/blob/ab9c8301cb9ae573ba597154ddeea16f0326fc15/gunicorn/http/body.py#L126-L130
    1010
    11 This is a feature of gunicorn, I think it relies on timing out when the reader doesn't have enough bytes
     11I think there's nothing to fix in django, it's something to work around in the networking layers (on my end I removed content-length from the client's request because I owned that piece as well). I'm not even sure how to fix gunicorn - maybe also check for some sort of EOF status of the incoming byte stream? As suggested above by Tim Graham, putting an nginx proxy in front of django and buffering your request seems like the best workaround:
    1212
    1313> I cannot reproduce when Django is behind a reverse proxy such as NGINX with proxy_request_buffering on which is the default.
    14 I believe this might be happening because proxy_request_buffering adds a correct content-length header after buffering the request on the nginx side? not sure I have the tools to verify this tbh so I would appreciate it if someone can confirm this
     14
     15I guess nginx with proxy_request_buffering adds a correct content-length header after buffering the request? not sure I have the tools to verify this tbh so I would appreciate it if someone can confirm this
Back to Top