FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Python 3.14.0a2 should have raised exception when a socket is already in used, shouldn't it? · Issue #127319 · python/cpython · GitHub

Repository navigation

Python 3.14.0a2 should have raised exception when a socket is already in used, shouldn't it? #127319

Closed

Description

Bug report

Bug description:

In earlier versions of Python all the way to 3.13, it would not allow a server to listen on a port that has already been used, and rightfully so.

$ python -m http.server 8000
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

# Trying to start the second server on the same port
$ python -m http.server 8000
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/lib/python3.11/http/server.py", line 1309, in <module>
    test(
  File "/usr/lib/python3.11/http/server.py", line 1256, in test
    with ServerClass(addr, HandlerClass) as httpd:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/socketserver.py", line 456, in __init__
    self.server_bind()
  File "/usr/lib/python3.11/http/server.py", line 1303, in server_bind
    return super().server_bind()
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/http/server.py", line 136, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/lib/python3.11/socketserver.py", line 472, in server_bind
    self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use

But in Python 3.14.0a2, the second command would also start a server without exception. Is that expected?

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Nov 27, 2024
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 27, 2024
  3. skirpichev commented on Nov 27, 2024

    Member

    I confirm this in the main. It seems, for two processes, the last started process - serves requests. If it's terminated - works the first.

    At least, seems as a documentation issue for me (nothing in news).

  4. oskar-skog commented on Nov 27, 2024

    I believe it's caused by this commit:
    192d17c

    See also comment: #120485 (comment)
    Maybe allow_reuse_port should default to False?

  5. rayluo commented on Nov 27, 2024

    Author

    I confirm this in the main. It seems, for two processes, the last started process - serves requests. If it's terminated - works the first.

    At least, seems as a documentation issue for me (nothing in news).

    Based on #120485 (comment) (thanks for the finding, @oskar-skog ), "the kernel may dispatch the request to different server process randomly", which is concerning.

    Maybe allow_reuse_port should default to False?

    +1

  6. musicinmybrain commented on Jun 4, 2025

    I can still reproduce this (and AzureAD/microsoft-authentication-library-for-python#768) on Python 3.14.0b2. Is there any plan to change this behavior before the 3.14.0 final release?

  7. added a commit that references this issue on Jun 11, 2025
  8. added a commit that references this issue on Jun 15, 2025
  9. added a commit that references this issue on Jun 15, 2025
  10. added a commit that references this issue on Jun 16, 2025
  11. added a commit that references this issue on Jun 16, 2025
  12. added a commit that references this issue on Jun 19, 2025
  13. added a commit that references this issue on Jul 12, 2025
  14. added a commit that references this issue on Aug 4, 2025
  15. added a commit that references this issue on Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL