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

Potential async-signal-safety issue in asyncio.Runner._on_sigint · Issue #158902 · python/cpython · GitHub

Repository navigation

Potential async-signal-safety issue in asyncio.Runner._on_sigint #158902

Description

Bug report

I don't have an actual failure to report: it's a potential issue I noticed while inspecting the code.

An asyncio.Runner on the main thread installs a SIGINT handler using signal.signal (and NOT loop.add_signal_handler for whatever reason). The signal handler could thus run at more-or-less any time and cannot rely on the asyncio machinery being in a consistent state. However, it directly interacts with the main task, calling main_task.done() and main_task.cancel():

    def _on_sigint(self, signum, frame, main_task):
        self._interrupt_count += 1
        if self._interrupt_count == 1 and not main_task.done():
            main_task.cancel()
            # wakeup loop if it is blocked by select() with long timeout
            self._loop.call_soon_threadsafe(lambda: None)
            return
        raise KeyboardInterrupt()

Task.cancel in particular seems like a complex piece of code that will depend on invariants, and that's before considering that one might have a user-provided event loop factory which in turn uses a custom task class.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

No activity

Activity on this issue will appear here.

Activity

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

    stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or error

    Projects

    • Status
      Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL