Skip to content

http.server raises exception if scanned with nmap #137710

@Zabolekar

Description

@Zabolekar

Bug report

Bug description:

To reproduce, open two terminal instances.

In one terminal instance, type python -m http.server. Output, as expected:

Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

In another terminal instance, type nmap -p 8000 localhost. As expected, it reports (relevant fragment):

PORT     STATE SERVICE
8000/tcp open  http-alt

In the first terminal instance, the following exception occurs:

Exception occurred during processing of request from ('127.0.0.1', 47284)
Traceback (most recent call last):
  File "/usr/lib/python3.11/socketserver.py", line 691, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python3.11/http/server.py", line 1306, in finish_request
    self.RequestHandlerClass(request, client_address, self,
  File "/usr/lib/python3.11/http/server.py", line 667, in __init__
    super().__init__(*args, **kwargs)
  File "/usr/lib/python3.11/socketserver.py", line 755, in __init__
    self.handle()
  File "/usr/lib/python3.11/http/server.py", line 432, in handle
    self.handle_one_request()
  File "/usr/lib/python3.11/http/server.py", line 400, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/socket.py", line 706, in readinto
    return self._sock.recv_into(b)
           ^^^^^^^^^^^^^^^^^^^^^^^
ConnectionResetError: [Errno 104] Connection reset by peer

CPython versions tested on:

3.13, 3.11

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions