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

asyncio sock_recv blocks on ssl sockets. #81585

Closed
blackblood mannequin opened this issue Jun 25, 2019 · 11 comments
Closed

asyncio sock_recv blocks on ssl sockets. #81585

blackblood mannequin opened this issue Jun 25, 2019 · 11 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes easy topic-asyncio topic-SSL type-bug An unexpected behavior, bug, or error

Comments

@blackblood
Copy link
Mannequin

blackblood mannequin commented Jun 25, 2019

BPO 37404
Nosy @tiran, @asvetlov, @1st1, @miss-islington, @blackblood, @idomic
PRs
  • bpo-37404: Raising value error if an SSLSocket is passed to asyncio functions #14457
  • bpo-37404: Raising value error if an SSLSocket is passed to asyncio functions #16457
  • [3.7] bpo-37404: Raising value error if an SSLSocket is passed to asyncio functions (GH-16457) #17495
  • [3.8] bpo-37404: Raising value error if an SSLSocket is passed to asyncio functions (GH-16457) #17496
  • bpo-37404: Fix check for ssl.SSLSocket #17526
  • Files
  • server_client: Server/Client Code to replicate the issue. Note: You'll have to create the certificate.pem and key.pem files
  • 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 = 'https://github.com/tiran'
    closed_at = <Date 2020-02-03.10:16:45.842>
    created_at = <Date 2019-06-25.19:36:21.829>
    labels = ['easy', 'expert-SSL', 'type-bug', '3.8', '3.9', '3.7', 'expert-asyncio']
    title = 'asyncio sock_recv blocks on ssl sockets.'
    updated_at = <Date 2020-02-03.10:16:45.841>
    user = 'https://github.com/blackblood'

    bugs.python.org fields:

    activity = <Date 2020-02-03.10:16:45.841>
    actor = 'asvetlov'
    assignee = 'christian.heimes'
    closed = True
    closed_date = <Date 2020-02-03.10:16:45.842>
    closer = 'asvetlov'
    components = ['asyncio', 'SSL']
    creation = <Date 2019-06-25.19:36:21.829>
    creator = 'AkshayTakkar'
    dependencies = []
    files = ['48437']
    hgrepos = []
    issue_num = 37404
    keywords = ['patch', 'easy', 'newcomer friendly']
    message_count = 11.0
    messages = ['346550', '346552', '346597', '346598', '346599', '353444', '357971', '357972', '357973', '358086', '361236']
    nosy_count = 6.0
    nosy_names = ['christian.heimes', 'asvetlov', 'yselivanov', 'miss-islington', 'AkshayTakkar', 'Ido Michael']
    pr_nums = ['14457', '16457', '17495', '17496', '17526']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue37404'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @blackblood
    Copy link
    Mannequin Author

    blackblood mannequin commented Jun 25, 2019

    I'm working on a server that uses sock_recv from asyncio.
    await sock_recv(socket, n) never returns if socket is wrapped in ssl using the wrap_socket function from the ssl module.
    I think the problem stated in this stackoverflow question could be the reason: https://stackoverflow.com/questions/40346619/behavior-of-pythons-select-with-partial-recv-on-ssl-socket

    @blackblood blackblood mannequin added the 3.7 (EOL) end of life label Jun 25, 2019
    @blackblood blackblood mannequin assigned tiran Jun 25, 2019
    @blackblood blackblood mannequin added topic-asyncio topic-SSL type-bug An unexpected behavior, bug, or error labels Jun 25, 2019
    @tiran
    Copy link
    Member

    tiran commented Jun 25, 2019

    You can't use sock_recv() with a wrapped SSL socket. A SSLSocket behaves differently because there is user-level buffering. The connection operates on TLS frames and only hands off data after it has been decrypted and verified. asyncio uses wrap_bio().

    @blackblood
    Copy link
    Mannequin Author

    blackblood mannequin commented Jun 26, 2019

    Can you please elaborate on how to get around this issue?

    @asvetlov
    Copy link
    Contributor

    Use asyncio transports or streams.
    sock_recv() is a low-level API with a very limited audience.

    wrapped ssl socket provides a synchronous interface only.

    Perhaps we should raise an exception if SSLSocket is passed into asyncio functions.

    @blackblood
    Copy link
    Mannequin Author

    blackblood mannequin commented Jun 26, 2019

    Ah, I see. Yes, raising an exception would probably be very useful. Thanks for the info.

    @idomic
    Copy link
    Mannequin

    idomic mannequin commented Sep 28, 2019

    Fixed this issue since the CLA of the past user wasn't signed.

    Added a check for the socket type in each of the methods:
    sock_recv, sock_recv_into, sock_sendall, sock_connect, sock_accept.

    PR: #60661

    @miss-islington
    Copy link
    Contributor

    New changeset 892f9e0 by Miss Islington (bot) (idomic) in branch 'master':
    bpo-37404: Raising value error if an SSLSocket is passed to asyncio functions (GH-16457)
    892f9e0

    @asvetlov
    Copy link
    Contributor

    asvetlov commented Dec 7, 2019

    New changeset 930cef2 by Andrew Svetlov in branch '3.8':
    [3.8] bpo-37404: Raising value error if an SSLSocket is passed to asyncio functions (GH-16457) (bpo-17496)
    930cef2

    @miss-islington
    Copy link
    Contributor

    New changeset a85066d by Miss Islington (bot) in branch '3.7':
    bpo-37404: Raising value error if an SSLSocket is passed to asyncio functions (GH-16457)
    a85066d

    @asvetlov asvetlov added 3.8 (EOL) end of life 3.9 only security fixes labels Dec 7, 2019
    @asvetlov asvetlov closed this as completed Dec 7, 2019
    @tiran
    Copy link
    Member

    tiran commented Dec 9, 2019

    The patch broke Python builds without ssl support and caused a minor performance regression in hot paths. I changed the code to only perform the check in debug mode.

    @tiran tiran reopened this Dec 9, 2019
    @idomic
    Copy link
    Mannequin

    idomic mannequin commented Feb 2, 2020

    Sorry it broke the version, what could I have done to avoid this?
    Also can we close this issue?

    @asvetlov asvetlov closed this as completed Feb 3, 2020
    @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
    3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes easy topic-asyncio topic-SSL type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants