Opened 9 years ago

Closed 8 years ago

#4669 defect closed fixed (fixed)

iocpreactor socket.error: [Errno 10014] The system detected an invalid pointer address in attempting to use a pointer argument in a call

Reported by: ghazel Owned by: Jean-Paul Calderone
Priority: normal Milestone:
Component: core Keywords: iocpreactor win32
Cc: Thijs Triemstra Branch: branches/iocp-win64-4669
branch-diff, diff-cov, branch-cov, buildbot
Author: exarkun

Description

This reminds me of #1346, but I'm not sure it's related.

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\twisted\python\log.py", line 84, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "C:\Python27\lib\site-packages\twisted\python\log.py", line 69, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "C:\Python27\lib\site-packages\twisted\python\context.py", line 59, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "C:\Python27\lib\site-packages\twisted\python\context.py", line 37, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "C:\Python27\lib\site-packages\twisted\internet\iocpreactor\reactor.py", line 114, in _callEventCallback
    evt.callback(rc, bytes, evt)
  File "C:\Python27\lib\site-packages\twisted\internet\iocpreactor\tcp.py", line 581, in cbAccept
    self.handleAccept(rc, evt)
  File "C:\Python27\lib\site-packages\twisted\internet\iocpreactor\tcp.py", line 598, in handleAccept
    struct.pack('I', self.socket.fileno()))
  File "C:\Python27\lib\socket.py", line 222, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 10014] The system detected an invalid pointer address in attempting to use a pointer argument in a call

Probably related, this an x86-64 build of Python:

Python 2.7 (r27:82525, Jul  4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32

Change History (14)

comment:1 Changed 9 years ago by Jean-Paul Calderone

Owner: changed from Glyph to ghazel

Any reproduction instructions?

comment:2 Changed 9 years ago by ghazel

Owner: changed from ghazel to Glyph

Just hit that code path. This does it:

from twisted.internet import iocpreactor
iocpreactor.install()
from twisted.internet import reactor, protocol

sf = protocol.ServerFactory()
sf.protocol = protocol.Protocol
reactor.listenTCP(10203, sf)

cf = protocol.ClientFactory()
cf.protocol = protocol.Protocol
reactor.connectTCP('localhost', 10203, cf)

reactor.run()

comment:3 Changed 9 years ago by Glyph

Owner: changed from Glyph to PenguinOfDoom

comment:4 Changed 9 years ago by <automation>

Owner: PenguinOfDoom deleted

comment:5 Changed 8 years ago by Mark Kolb

I encountered this bug as well, and found a fix for it. In twisted/iocpreactor/tcp.py, there are two different lines that make the following call:

struct.pack('I', self.socket.fileno())

For 64-bit Windows, this call instead needs to be:

struct.pack('Q', self.socket.fileno())

comment:6 Changed 8 years ago by Thijs Triemstra

Cc: Thijs Triemstra added

comment:7 Changed 8 years ago by Jean-Paul Calderone

Keywords: win32 added

Cool! It looks like there's enough information to write a unit test for this, and the patch should be simple. One thing I'm not sure about yet is why none of the existing unit tests catch this. It looks like the reproduction just sets up one TCP connection. Lots of unit tests do that.

comment:8 Changed 8 years ago by ghazel

Is there a x86-64 test slave running an x86-64 build of Python? The unit tests do not pass for me - the first test_tcp test, twisted.test.test_tcp.test_buildProtocolClient, hangs forever.

comment:9 Changed 8 years ago by Jean-Paul Calderone

Ah! x86-64 Python, I see. We do not have a slave running that.

comment:10 Changed 8 years ago by Jean-Paul Calderone

Author: exarkun
Branch: branches/iocp-win64-4669

(In [33017]) Branching to 'iocp-win64-4669'

comment:11 Changed 8 years ago by Jean-Paul Calderone

Keywords: review added

We have a 64 bit Windows slave now. build results

comment:12 Changed 8 years ago by Glyph

Owner: set to Jean-Paul Calderone

Looks good to me. The builder is actually green, even. And P is definitely the right value, not Q :).

comment:13 Changed 8 years ago by Glyph

Keywords: review removed

comment:14 Changed 8 years ago by Jean-Paul Calderone

Resolution: fixed
Status: newclosed

(In [33047]) Merge iocp-win64-4669

Author: exarkun Reviewer: glyph Fixes: #4669

Change IOCP reactor to pack socket descriptor numbers into a string of the correct size for the platform - the size of a pointer, rather than the size of an integer - so the setsockopt() call succeeds instead of failing with an error about an invalid pointer.

Note: See TracTickets for help on using tickets.