Skip to content

Clearer assertion error #84305

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

Closed
pgjones mannequin opened this issue Mar 31, 2020 · 7 comments
Closed

Clearer assertion error #84305

pgjones mannequin opened this issue Mar 31, 2020 · 7 comments
Labels
3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes topic-asyncio

Comments

@pgjones
Copy link
Mannequin

pgjones mannequin commented Mar 31, 2020

BPO 40124
Nosy @ericvsmith, @asvetlov, @cjerdonek, @1st1, @mhils, @pgjones, @aeros
PRs
  • bpo-40124: Explain an assert when waiting on a asyncio stream drain #19240
  • 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 2020-03-31.11:34:58.777>
    labels = ['3.7', '3.8', '3.9', '3.10', 'expert-asyncio']
    title = 'Clearer assertion error'
    updated_at = <Date 2022-02-27.06:48:02.515>
    user = 'https://github.com/pgjones'

    bugs.python.org fields:

    activity = <Date 2022-02-27.06:48:02.515>
    actor = 'mhils'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['asyncio']
    creation = <Date 2020-03-31.11:34:58.777>
    creator = 'pgjones'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40124
    keywords = ['patch']
    message_count = 6.0
    messages = ['365378', '365381', '365568', '369332', '376643', '414142']
    nosy_count = 8.0
    nosy_names = ['eric.smith', 'asvetlov', 'chris.jerdonek', 'yselivanov', 'mhils', 'pgjones', 'aeros', 'udifuchs']
    pr_nums = ['19240']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue40124'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10']

    @pgjones
    Copy link
    Mannequin Author

    pgjones mannequin commented Mar 31, 2020

    https://discuss.python.org/t/assertionerror-asyncio-streams-in-drain-helper/3743/4

    I recently came across this error, which I now know how to fix. I think the error can be clearer and I've a PR which I think does so.

    @pgjones pgjones mannequin added 3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes topic-asyncio labels Mar 31, 2020
    @ericvsmith
    Copy link
    Member

    Do we really want this to be just an assert, or do we want to raise another type of exception? I think it's showing a real programming error that we wouldn't want to throw away with -O.

    @aeros
    Copy link
    Contributor

    aeros commented Apr 2, 2020

    Do we really want this to be just an assert, or do we want to raise another type of exception?

    IMO, we should look into converting this into an exception. Mistakenly having a task await StreamWriter.drain() at the same time as another is calling StreamWriter.write() does seem like a reasonable programming error that should preferably have an informative error message. Optimally, assertions shouldn't occur from normal programming errors in production.

    The tricky part is figuring out how to implement it properly. I'm not 100% certain that we can make any guarantees that when the _drain_waiter future hasn't been cancelled and not set to None that someone is mistakenly doing the above. It could potentially trigger from other errors.

    Either way though, I think just adding a message to the assert could end up being misleading if someone else encounters this in production for another reason. Instead, I think we could leave a comment there for now and in the long term figure out how to properly implement the exception or warning. We also need a reliable way to reproduce it, mainly for the purpose of writing a new test to ensure the exception is correctly triggered when someone makes the above programming error.

    @cjerdonek
    Copy link
    Member

    How about we review Phil's PR, which adds a message to the assertion. And then we can keep this issue open to discuss converting the assertion to an exception. I think Phil's PR is an improvement.

    @udifuchs
    Copy link
    Mannequin

    udifuchs mannequin commented Sep 9, 2020

    I don't see anything in the documentation of drain() that states that it cannot be called from multiple tasks.

    I'm also not sure why this assertion is necessary. If self._drain_waiter is already set, could the other task just await on it?

    @mhils
    Copy link
    Mannequin

    mhils mannequin commented Feb 27, 2022

    I'm pretty sure this issue is a duplicate of bpo-issue29930.

    @mhils mhils mannequin added 3.10 only security fixes labels Feb 27, 2022
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @ezio-melotti ezio-melotti moved this to Todo in asyncio Jul 17, 2022
    @kumaraditya303
    Copy link
    Contributor

    Duplicate of #74116

    @kumaraditya303 kumaraditya303 marked this as a duplicate of #74116 Sep 9, 2022
    @kumaraditya303 kumaraditya303 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 9, 2022
    Repository owner moved this from Todo to Done in asyncio Sep 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes topic-asyncio
    Projects
    Status: Done
    Development

    No branches or pull requests

    4 participants