-
-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
socket.connect_ex return wrongly #125632
Comments
In your |
Sry, I did not cite all of my server code. Here is the whole file # server.py
sockets = [s]
while True:
readable, writable, exceptional = select.select(sockets, [], sockets)
for s in readable:
if s is sockets[0]:
conn, addr = s.accept()
sockets.append(conn)
print("Connected to ", addr)
else:
data = s.recv(1024)
if data:
print("Received data: ", data)
else:
print("Connection closed")
s.close()
sockets.remove(s)
continue
for s in exceptional:
print("Exceptional condition")
s.close()
sockets.remove(s)
continue Actually, the server will know the connection is built. But |
Confirm this issue is exist on main branch. Plz assign this issue to me, I will find the root cause |
I see you requested assignment here as well: #125641 Typically, assignment isn't necessary--just leave a comment saying that you're working on it, and that's enough to prevent someone from beating you to it (you don't need to be assigned to the issue to submit a PR). But first, it's a good idea to ask the issue author if they would like to author the fix. I'll assign this to you because we need contributors, but let's not make this a habit :) Please ping me if you would like to have your assignment removed--some issues are more complicated than they originally seem. |
I think this not a bug, is excepted behavior
|
So if I set socket to nonblocking. I cannot use that |
We have already describe the behavior in the documents
In your circumstance, if you try to use |
10056 is the Windows error code. FYI https://learn.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2. This part is not belong to CPython. In |
I just test same code on linux. Both blocking and nonblocking situation can output a 0. So this is a bug when using Thank you for your time and help! |
Thank you for dealing with this @Zheaoli! Should this get closed? |
I think this issue should be closed. We can not take care all the behavior of the syscall under the API. The developer need to take care of the detail from the document which is belong to the platform they are using |
Bug report
Bug description:
According to
connect_ex
doc, it should return 0 if connection is successful. Here I start client first and keepconnect_ex
to test if it connects successfully.When I start server, the
connect_ex
should succeed and return 0. However, if nonblocking is set on client socket, it will return non-zero even if the connection is successful. If nonblocking is not set, it works good.CPython versions tested on:
3.11
Operating systems tested on:
Windows
The text was updated successfully, but these errors were encountered: