8000 gh-69282: test_httpservers hangs since Python 3.5 by WildCard65 · Pull Request #9564 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-69282: test_httpservers hangs since Python 3.5 #9564

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion Lib/test/test_httpservers.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,10 @@ class request_handler(BaseHTTPRequestHandler):
default_request_version = 'HTTP/1.1'

def do_GET(self):
# gh-69282: Tell the client we're not sending any content along
# with the response code.
self.send_response(HTTPStatus.OK)
self.send_header('Content-Length', 0)
Copy link
Member

Choose a reason for hiding this comment

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

(Nitpick) It’s not really documented, and seems to work regardless, but I assume the header field value should be a string '0' not an integer

self.end_headers()

def do_ERROR(self):
Expand All @@ -331,8 +334,15 @@ def test_get(self):
self.con.connect()

with support.captured_stderr() as err:
self.con.request('GET', '/')
# gh-69282: HTTP/1.1 specifies that the socket connection is to
# remain open, this, on certain systems, causes Python to deadlock
# waiting for the socket to close.
# To combat this, we send the test server the "Connection" header
# with "close" for the value forcing the server and client to
# terminate the socket allowing the test to resume.
self.con.request('GET', '/', headers={'Connection': 'close'})
Copy link
Member

Choose a reason for hiding this comment

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

The explanation seems vague. I would explain it as:

“Connection: close” causes the server to set its “close_connection” flag. If the client did not also shut down the connection below, this flag would avoid a deadlock between the server waiting for a second request on the connection, and the main thread shutting the server down.

self.con.getresponse()
self.con.close()

self.assertTrue(
err.getvalue().endswith('"GET / HTTP/1.1" 200 -\n'))
Expand Down
Loading
0