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

socketserver.BaseServer.handle_error() should not catch exiting exceptions #67618

Closed
vadmium opened this issue Feb 10, 2015 · 7 comments
Closed
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@vadmium
Copy link
Member

vadmium commented Feb 10, 2015

BPO 23430
Nosy @pitrou, @berkerpeksag, @vadmium
Files
  • socketserver-exit.patch
  • socketserver-exit.v2.patch
  • socketserver-exit.v3.patch
  • socketserver-exit.v4.patch
  • socketserver-exit.v5.patch
  • socketserver-exit.v6.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 2016-02-22.09:07:41.876>
    created_at = <Date 2015-02-10.03:34:07.961>
    labels = ['type-feature', 'library']
    title = 'socketserver.BaseServer.handle_error() should not catch exiting exceptions'
    updated_at = <Date 2016-02-22.09:07:41.875>
    user = 'https://github.com/vadmium'

    bugs.python.org fields:

    activity = <Date 2016-02-22.09:07:41.875>
    actor = 'martin.panter'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-02-22.09:07:41.876>
    closer = 'martin.panter'
    components = ['Library (Lib)']
    creation = <Date 2015-02-10.03:34:07.961>
    creator = 'martin.panter'
    dependencies = []
    files = ['38074', '38144', '38717', '38718', '41911', '41967']
    hgrepos = []
    issue_num = 23430
    keywords = ['patch']
    message_count = 7.0
    messages = ['235662', '236022', '239454', '239455', '260209', '260503', '260605']
    nosy_count = 4.0
    nosy_names = ['pitrou', 'python-dev', 'berker.peksag', 'martin.panter']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue23430'
    versions = ['Python 3.6']

    @vadmium
    Copy link
    Member Author

    vadmium commented Feb 10, 2015

    I propose changing the socket servers to not suppress exceptions that are meant to exit the interpreter. This is most applicable to single threaded servers, but my patch does the same thing for multithreading servers. It no longer catches exceptions that are not derived from the Exception class, such as KeyboardInterrupt and SystemExit. The shutdown_request() method is still called in all cases though.

    I also added a test for the forking server’s handle_error() method.

    @vadmium vadmium added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Feb 10, 2015
    @vadmium
    Copy link
    Member Author

    vadmium commented Feb 15, 2015

    Looking at this again, I think I should make the forking server’s handle_error() method only be called for Exception subclasses as well. So I am posting a new patch that also does this.

    @vadmium
    Copy link
    Member Author

    vadmium commented Mar 28, 2015

    Patch v3:

    • Changed the structure of exception handling for the forking server so that there is only one os._exit(status) call site
    • Rewrote tests to log results to a temporary file. This avoids sending a string of code to a Python subprocess. I use threading.Event and os.waitpid() to synchronize.
    • Tests now call the handle_request() public API, and create a trivial TCP connection to trigger a request.
    • Added doc string explaining simple_subprocess()

    Let me know what you think.

    @vadmium
    Copy link
    Member Author

    vadmium commented Mar 28, 2015

    Oops I forgot to refresh the patch. Patch v4 also closes the server in the tests.

    @vadmium
    Copy link
    Member Author

    vadmium commented Feb 12, 2016

    Here is an updated version for 3.6. I also wrote an entry for What’s New. It seems my change could help people trying to make a single-threaded server quit the server loop (bpo-13749).

    @vadmium
    Copy link
    Member Author

    vadmium commented Feb 19, 2016

    Thanks for the reivew Berker. I have merged the patch with recent changes and updated according to your comments.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 21, 2016

    New changeset d500d1a9615f by Martin Panter in branch 'default':
    Issue bpo-23430: Stop socketserver from catching SystemExit etc from handlers
    https://hg.python.org/cpython/rev/d500d1a9615f

    @vadmium vadmium closed this as completed Feb 22, 2016
    @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-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant