Skip to content

set better defaults for TCPServer options #80184

Open
@giampaolo

Description

@giampaolo
BPO 36003
Nosy @taleinat, @giampaolo, @asvetlov, @1st1
PRs
  • bpo-36003: change socketserver.TCPServer reuse_addr and backlog default options #11875
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2019-02-15.13:44:39.433>
    labels = ['easy', '3.8', 'type-feature', 'library']
    title = 'set better defaults for TCPServer options'
    updated_at = <Date 2019-06-08.18:18:49.463>
    user = 'https://github.com/giampaolo'

    bugs.python.org fields:

    activity = <Date 2019-06-08.18:18:49.463>
    actor = 'taleinat'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2019-02-15.13:44:39.433>
    creator = 'giampaolo.rodola'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36003
    keywords = ['patch', 'easy']
    message_count = 3.0
    messages = ['335612', '335614', '345058']
    nosy_count = 5.0
    nosy_names = ['taleinat', 'giampaolo.rodola', 'asvetlov', 'neologix', 'yselivanov']
    pr_nums = ['11875']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue36003'
    versions = ['Python 3.8']

    Linked PRs

    Activity

    giampaolo

    giampaolo commented on Feb 15, 2019

    @giampaolo
    ContributorAuthor

    socketserver.TCPServer provides the following defaults:

    allow_reuse_address = False
    request_queue_size = 5

    Proposal is to:

    • have "allow_reuse_address = True" on POSIX in order to immediately reuse previous sockets which were bound on the same address and remained in TIME_WAIT state
    • have "request_queue_size = None" so that it's up to socket.listen() to choose a default reasonable value (usually 128)
    giampaolo

    giampaolo commented on Feb 15, 2019

    @giampaolo
    ContributorAuthor

    Update: because "request_queue_size" is passed to server_activate() method which can be subclassed, a better default for not breaking backward compatibility is 0 (not None).

    taleinat

    taleinat commented on Jun 8, 2019

    @taleinat
    Contributor

    I'm not sure that changing the default value for "reuse address" justifies breaking backwards compatibility like this. Admittedly, I'm not an expert on networking, so perhaps there's a good reason that I'm unaware of.

    As for the queue size, passing 0 to socket.listen() does seem like a more reasonable default than the rather arbitrary value of 5. Again, it's arguable whether it's worth changing this given that it has been like this for a long time, but in this case at least the potential for harm seems negligible.

    transferred this issue fromon Apr 10, 2022
    gpshead

    gpshead commented on May 19, 2025

    @gpshead
    Member

    agreed, lets use 0 as the queue size but leave reuse address alone.

    gpshead

    gpshead commented on May 19, 2025

    @gpshead
    Member

    (we're working out if we even want to that on the PR, see comments there)

    added a commit that references this issue on May 19, 2025

    gh-80184: Set getattr(socket, "SOMAXCONN", 5) as the default queue si…

    92f85ff
    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

      easystdlibPython modules in the Lib dirtype-featureA feature request or enhancement

      Projects

      No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        set better defaults for TCPServer options · Issue #80184 · python/cpython

        Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

        Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant