This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: test_socket.testDup, testFromFd fail on Windows
Type: behavior Stage: resolved
Components: Library (Lib), Windows Versions: Python 3.1, Python 3.2
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: stutzbach Nosy List: amaury.forgeotdarc, brian.curtin, christian.heimes, roudkerk, stutzbach, tim.golden
Priority: normal Keywords: patch

Created on 2010-09-03 10:16 by stutzbach, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue9753.patch stutzbach, 2010-09-03 11:51
Messages (7)
msg115432 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-03 10:16
The errors below show up on my XP machine in Python 3.1 as well as a recent build from the py3k branch.  I'm not sure why they *don't* show up on the XP buildbot.

fromfd() ultimately calls dup(), so the underlying problem is likely the same for all the failures.  dup() support was added for Windows in issue1378.

======================================================================
ERROR: testDup (test.test_socket.BasicTCPTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python31\lib\test\test_socket.py", line 628, in testDup
    msg = sock.recv(1024)
socket.error: [Errno 10038] An operation was attempted on something that is not a socket

======================================================================
ERROR: testFromFd (test.test_socket.BasicTCPTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python31\lib\test\test_socket.py", line 619, in testFromFd
    msg = sock.recv(1024)
socket.error: [Errno 10038] An operation was attempted on something that is not a socket

======================================================================
ERROR: testDup (test.test_socket.BasicTCPTest2)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python31\lib\test\test_socket.py", line 628, in testDup
    msg = sock.recv(1024)
socket.error: [Errno 10045] The attempted operation is not supported for the type of object referenced

======================================================================
ERROR: testFromFd (test.test_socket.BasicTCPTest2)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python31\lib\test\test_socket.py", line 619, in testFromFd
    msg = sock.recv(1024)
socket.error: [Errno 10038] An operation was attempted on something that is not a socket

----------------------------------------------------------------------
msg115438 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-09-03 11:15
test_socket.py passes here.
I run: python_d.exe -m test.regrtest -v test_socket
msg115439 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-03 11:16
I run it the same way.

I wonder what's different? :-(  I will try to find some time to investigate further.
msg115440 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-03 11:25
On Windows, socket.dup is implemented using DuplicateHandle.  The documentation for DuplicateHandle reads:

You should not use DuplicateHandle to duplicate handles to the following objects:

    * I/O completion ports. No error is returned, but the duplicate handle cannot be used.
    * Sockets. No error is returned, but the duplicate handle may not be recognized by Winsock at the target process. Also, using DuplicateHandle interferes with internal reference counting on the underlying object. To duplicate a socket handle, use the WSADuplicateSocket function.
msg115442 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-03 11:51
Following the advice of DuplicateHandle's documentation, I reimplemented dup on Windows using WSADuplicateHandle.  Attached is a patch.  With the patch, the tests pass on my Windows machine.

Would someone like to review the patch?
msg115443 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-09-03 12:05
The documentation of WSASocket(), and the code of PyBluez
http://code.google.com/p/pybluez/source/browse/trunk/msbt/_msbt.c#374
both suggest to use the FROM_PROTOCOL_INFO constant.
Otherwise, the patch looks good.
msg115448 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-03 12:43
Thanks!  Updated as you suggested and committed as r84450 and r84451.
History
Date User Action Args
2022-04-11 14:57:06adminsetgithub: 53962
2010-09-03 12:43:05stutzbachsetstatus: open -> closed
keywords: - needs review
messages: + msg115448

stage: patch review -> resolved
2010-09-03 12:05:25amaury.forgeotdarcsetmessages: + msg115443
2010-09-03 11:51:49stutzbachsetfiles: + issue9753.patch
2010-09-03 11:51:18stutzbachsetmessages: + msg115442

assignee: stutzbach
keywords: + patch, needs review
resolution: accepted
stage: patch review
2010-09-03 11:25:23stutzbachsetmessages: + msg115440
2010-09-03 11:16:33stutzbachsetmessages: + msg115439
2010-09-03 11:15:08amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg115438
2010-09-03 10:16:05stutzbachcreate