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

test_socket.testDup, testFromFd fail on Windows #53962

Closed
stutzbach mannequin opened this issue Sep 3, 2010 · 7 comments
Closed

test_socket.testDup, testFromFd fail on Windows #53962

stutzbach mannequin opened this issue Sep 3, 2010 · 7 comments
Labels
OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@stutzbach
Copy link
Mannequin

stutzbach mannequin commented Sep 3, 2010

BPO 9753
Nosy @amauryfa, @tiran, @tjguk, @briancurtin
Files
  • issue9753.patch
  • 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 = <Date 2010-09-03.12:43:05.760>
    created_at = <Date 2010-09-03.10:16:05.535>
    labels = ['type-bug', 'library', 'OS-windows']
    title = 'test_socket.testDup, testFromFd fail on Windows'
    updated_at = <Date 2010-09-03.12:43:05.758>
    user = 'https://bugs.python.org/stutzbach'

    bugs.python.org fields:

    activity = <Date 2010-09-03.12:43:05.758>
    actor = 'stutzbach'
    assignee = 'stutzbach'
    closed = True
    closed_date = <Date 2010-09-03.12:43:05.760>
    closer = 'stutzbach'
    components = ['Library (Lib)', 'Windows']
    creation = <Date 2010-09-03.10:16:05.535>
    creator = 'stutzbach'
    dependencies = []
    files = ['18724']
    hgrepos = []
    issue_num = 9753
    keywords = ['patch']
    message_count = 7.0
    messages = ['115432', '115438', '115439', '115440', '115442', '115443', '115448']
    nosy_count = 6.0
    nosy_names = ['amaury.forgeotdarc', 'christian.heimes', 'tim.golden', 'roudkerk', 'stutzbach', 'brian.curtin']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue9753'
    versions = ['Python 3.1', 'Python 3.2']

    @stutzbach
    Copy link
    Mannequin Author

    stutzbach mannequin commented Sep 3, 2010

    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 bpo-1378.

    ======================================================================
    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

    @stutzbach stutzbach mannequin added stdlib Python modules in the Lib dir OS-windows type-bug An unexpected behavior, bug, or error labels Sep 3, 2010
    @amauryfa
    Copy link
    Member

    amauryfa commented Sep 3, 2010

    test_socket.py passes here.
    I run: python_d.exe -m test.regrtest -v test_socket

    @stutzbach
    Copy link
    Mannequin Author

    stutzbach mannequin commented Sep 3, 2010

    I run it the same way.

    I wonder what's different? :-( I will try to find some time to investigate further.

    @stutzbach
    Copy link
    Mannequin Author

    stutzbach mannequin commented Sep 3, 2010

    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.
    

    @stutzbach
    Copy link
    Mannequin Author

    stutzbach mannequin commented Sep 3, 2010

    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?

    @stutzbach stutzbach mannequin self-assigned this Sep 3, 2010
    @amauryfa
    Copy link
    Member

    amauryfa commented Sep 3, 2010

    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.

    @stutzbach
    Copy link
    Mannequin Author

    stutzbach mannequin commented Sep 3, 2010

    Thanks! Updated as you suggested and committed as r84450 and r84451.

    @stutzbach stutzbach mannequin closed this as completed Sep 3, 2010
    @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
    OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant