Skip to content
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

Uses of SocketServer.BaseServer.shutdown have a race #46555

Closed
jyasskin mannequin opened this issue Mar 16, 2008 · 6 comments
Closed

Uses of SocketServer.BaseServer.shutdown have a race #46555

jyasskin mannequin opened this issue Mar 16, 2008 · 6 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@jyasskin
Copy link
Mannequin

jyasskin mannequin commented Mar 16, 2008

BPO 2302
Nosy @pitrou, @giampaolo
Files
  • race_free_shutdown.patch
  • shutdown.patch
  • 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 = <Date 2010-04-25.22:28:59.672>
    created_at = <Date 2008-03-16.15:15:55.330>
    labels = ['type-bug', 'library']
    title = 'Uses of SocketServer.BaseServer.shutdown have a race'
    updated_at = <Date 2010-04-25.22:28:59.671>
    user = 'https://bugs.python.org/jyasskin'

    bugs.python.org fields:

    activity = <Date 2010-04-25.22:28:59.671>
    actor = 'pitrou'
    assignee = 'jyasskin'
    closed = True
    closed_date = <Date 2010-04-25.22:28:59.672>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2008-03-16.15:15:55.330>
    creator = 'jyasskin'
    dependencies = []
    files = ['9681', '16964']
    hgrepos = []
    issue_num = 2302
    keywords = ['patch']
    message_count = 6.0
    messages = ['63579', '66364', '103431', '103433', '103626', '104173']
    nosy_count = 4.0
    nosy_names = ['pitrou', 'giampaolo.rodola', 'jyasskin', 'zanella']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue2302'
    versions = ['Python 2.6', 'Python 3.1', 'Python 2.7', 'Python 3.2']

    @jyasskin
    Copy link
    Mannequin Author

    jyasskin mannequin commented Mar 16, 2008

    With the code as it stands, calls to shutdown that happen before
    serve_forever enters its loop will deadlock, and there's no simple way
    for the user to avoid this. The attached patch prevents the deadlock and
    allows multiple serve_forever..shutdown cycles, but it's pretty
    complicated. I could make it a lot simpler by making shutdown permanent:
    any later serve_forever calls would return immediately.

    A third choice would be to add a .serve_in_thread function that returns
    a token that can be used to shut down exactly that loop, instead of
    putting .shutdown() on the server. Any opinions?

    @jyasskin jyasskin mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 16, 2008
    @jyasskin jyasskin mannequin self-assigned this Mar 16, 2008
    @zanella
    Copy link
    Mannequin

    zanella mannequin commented May 7, 2008

    With the code as it stands, calls to shutdown that happen before
    serve_forever enters its loop will deadlock, and there's no simple way
    for the user to avoid this. The attached patch prevents the deadlock and
    allows multiple serve_forever..shutdown cycles, but it's pretty
    complicated. I could make it a lot simpler by making shutdown permanent:
    any later serve_forever calls would return immediately.

    Never thought of using the SocketServer taht way, wouldn't the person
    doing this bunch of shutdown()s and serve_forever()s be better off using
    handle_request() on a loop instead ?

    A third choice would be to add a .serve_in_thread function that returns
    a token that can be used to shut down exactly that loop, instead of
    putting .shutdown() on the server. Any opinions?

    I don't think I understand this part, what loop do you refer to ?

    @pitrou
    Copy link
    Member

    pitrou commented Apr 17, 2010

    After a bit of investigation, this issue seems to be exactly why test_httpservers sometimes hangs.
    The patch looks complicated to me, though; I don't think we really have to support the multiple shutdowns case.

    @pitrou
    Copy link
    Member

    pitrou commented Apr 17, 2010

    Here is a simpler patch. It also fixes the wrong use of a lock instead of an event in test_httpservers. With this patch, test_httpservers runs forever without freezing.

    @pitrou
    Copy link
    Member

    pitrou commented Apr 19, 2010

    By the way, getting rid of poll_interval for a file descriptor is easy under Unix, but wouldn't work under Windows (where select() only takes sockets, not arbitrary file descriptors).

    @pitrou
    Copy link
    Member

    pitrou commented Apr 25, 2010

    Fixed with a test in r80484 (trunk), r80486 (2.6), r80487 (py3k), r80491 (3.1).

    @pitrou pitrou closed this as completed Apr 25, 2010
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant