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

Fix request body handling in gthread worker #3303

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions THANKS
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,4 @@ Xie Shi <[email protected]>
Yue Du <[email protected]>
zakdances <[email protected]>
Emile Fugulin <[email protected]>
Oliver Allen <[email protected]>
12 changes: 7 additions & 5 deletions gunicorn/http/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ def __init__(self, cfg, source, source_addr):
def __iter__(self):
return self

def __next__(self):
# Stop if HTTP dictates a stop.
if self.mesg and self.mesg.should_close():
raise StopIteration()

def finish_body(self):
# Discard any unread body of the previous message
if self.mesg:
data = self.mesg.body.read(8192)
while data:
data = self.mesg.body.read(8192)

def __next__(self):
# Stop if HTTP dictates a stop.
if self.mesg and self.mesg.should_close():
raise StopIteration()
self.finish_body()

# Parse the next request
self.req_count += 1
self.mesg = self.mesg_class(self.cfg, self.unreader, self.source_addr, self.req_count)
Expand Down
1 change: 1 addition & 0 deletions gunicorn/workers/gthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ def handle(self, conn):
# handle the request
keepalive = self.handle_request(req, conn)
if keepalive:
conn.parser.finish_body()
return (keepalive, conn)
except http.errors.NoMoreData as e:
self.log.debug("Ignored premature client disconnection. %s", e)
Expand Down