Skip to content

asyncio ProactorEventLoop didn't check if the socket is blocking #113892

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
NewUserHa opened this issue Jan 10, 2024 · 2 comments
Closed

asyncio ProactorEventLoop didn't check if the socket is blocking #113892

NewUserHa opened this issue Jan 10, 2024 · 2 comments
Assignees
Labels
topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@NewUserHa
Copy link
Contributor

NewUserHa commented Jan 10, 2024

Bug report

Bug description:

import asyncio
import socket

s = socket.socket()
await asyncio.get_running_loop().sock_connect(s,('127.0.0.1',80))

according to https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.sock_connect and

async def sock_connect(self, sock, address):
"""Connect to a remote socket at address.
This method is a coroutine.
"""
base_events._check_ssl_socket(sock)
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
if sock.family == socket.AF_INET or (
base_events._HAS_IPv6 and sock.family == socket.AF_INET6):
resolved = await self._ensure_resolved(
address, family=sock.family, type=sock.type, proto=sock.proto,
loop=self,

it should raise. however, ProactorEventLoop doesn't follow the rule

should we fix this, any thoughts

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Linked PRs

@NewUserHa NewUserHa added the type-bug An unexpected behavior, bug, or error label Jan 10, 2024
@github-project-automation github-project-automation bot moved this to Todo in asyncio Jan 10, 2024
@gvanrossum
Copy link
Member

Oh, interesting. The question is, does async sending and receiving using that blocked socket work when using the ProactorEventLoop? Given how different IOCP is, it wouldn't surprise me if it did. Can you write a small test to check that? (There are probably tests you can adapt.)

@NewUserHa
Copy link
Contributor Author

ok

@Eclips4 Eclips4 self-assigned this May 24, 2024
Eclips4 added a commit to Eclips4/cpython that referenced this issue May 24, 2024
…ure that the given socket is in non-blocking mode
gvanrossum pushed a commit that referenced this issue Jun 1, 2024
…nsure that the given socket is in non-blocking mode (#119519)
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 1, 2024
…` to ensure that the given socket is in non-blocking mode (pythonGH-119519)

(cherry picked from commit cf3bba3)

Co-authored-by: Kirill Podoprigora <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 1, 2024
…` to ensure that the given socket is in non-blocking mode (pythonGH-119519)

(cherry picked from commit cf3bba3)

Co-authored-by: Kirill Podoprigora <[email protected]>
@github-project-automation github-project-automation bot moved this from Todo to Done in asyncio Jun 1, 2024
gvanrossum pushed a commit that referenced this issue Jun 1, 2024
…t` to ensure that the given socket is in non-blocking mode (GH-119519) (#119912)

(cherry picked from commit cf3bba3)

Co-authored-by: Kirill Podoprigora <[email protected]>
gvanrossum pushed a commit that referenced this issue Jun 1, 2024
…t` to ensure that the given socket is in non-blocking mode (GH-119519) (#119913)

(cherry picked from commit cf3bba3)

Co-authored-by: Kirill Podoprigora <[email protected]>
barneygale pushed a commit to barneygale/cpython that referenced this issue Jun 5, 2024
…` to ensure that the given socket is in non-blocking mode (python#119519)
noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
…` to ensure that the given socket is in non-blocking mode (python#119519)
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
…` to ensure that the given socket is in non-blocking mode (python#119519)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-asyncio type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

3 participants