Visitar URL original
HTTPSever.handle_request not respecting timeout as documented between first and second request · Issue #102156 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20260620230948/https://github.com/python/cpython/issues/102156
Skip to content
/ cpython Public

HTTPSever.handle_request not respecting timeout as documented between first and second request #102156

@eXhumer

Description

@eXhumer

Bug report

The HTTPServer times out as expected before receiving the first request and after receiving the second request. However, HTTPServer doesn't timeout as expected between the first and second request, blocking until the second request is received by HTTPServer.

Your environment

  • CPython versions tested on: 3.11.1
  • Operating system and architecture: Windows 11 22H2 x64

Example code demonstrating the issue

from http.server import BaseHTTPRequestHandler, HTTPServer


class HelloWorldHTTPRequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header("Content-Type", "text/plain")
        self.end_headers()
        self.wfile.write("Hello World!".encode("utf8"))


if __name__ == "__main__":
    httpd = HTTPServer(("localhost", 65012), HelloWorldHTTPRequestHandler)
    httpd.timeout = 1

    while True:
        try:
            print("handle_request")
            httpd.handle_request()

        except KeyboardInterrupt:
            break

Example code output

handle_request
handle_request
handle_request
handle_request
127.0.0.1 - - [22/Feb/2023 14:49:14] "GET / HTTP/1.1" 200 -
handle_request
127.0.0.1 - - [22/Feb/2023 14:49:29] "GET / HTTP/1.1" 200 -
handle_request
handle_request
handle_request
handle_request
handle_request
handle_request
handle_request
handle_request
handle_request
KeyboardInterrupt

Linked PRs

Metadata

Metadata

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions