Opened 13 months ago

Last modified 6 months ago

#10052 defect new

Issue with IOCPReactor's handling of WSAECONNREFUSED

Reported by: Mark Bishop Owned by: Xander Desai
Priority: normal Milestone:
Component: core Keywords:
Cc: Xander Desai Branch:
Author:

Description

The following code produces buggy behavior on Windows 2016 Server

import socket

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


class Receiver(DatagramProtocol):
    def datagramReceived(self, data, address):
        print("received %r from %r" % (data, address))


def sender():
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.sendto(b"test packet", ("127.0.0.1", 9999)) # never received by the protocol


server = Receiver()
reactor.listenUDP(9999, server)
reactor.callWhenRunning(server.transport.write, b"invalid write", ("127.0.0.1", 61000))
reactor.callWhenRunning(server.transport.write, b"invalid write", ("127.0.0.1", 61000))
reactor.callLater(1, sender)
reactor.run()

Queuing up two writes to a dead socket simultaneously will cause the IOCP subsystem to respond with a return code of 10054 (WSAECONNREFUSED) after which the Receiver will no longer be considered in the reactor event loop iteration. Meaning, in the above code, that datagramRecieved is not called in response to the test packet sent 1 second after the reactor starts.

I have confirmed that this occurs only with the IOCPReactor

It's possible that the error code is only a symptom of an underlying issue but it's the most reliable indicator of this problem occurring that I've found.

If the two writes are spaced more then a second apart then the issue no longer occurs.

I'm using Twisted 20.3.0 with Python 3.8.4

Change History (6)

comment:1 Changed 13 months ago by Xander Desai

Cc: Xander Desai added

comment:2 Changed 12 months ago by Xander Desai

Keywords: review added

Pull request that fixes this bug is here: https://github.com/twisted/twisted/pull/1482

comment:3 Changed 11 months ago by Xander Desai

Hi, Just trying to bump this to see if I can get any eyes on this PR. Let me know if there's any other things I can provide to help get this bug fixed. Thanks, Xander

comment:4 Changed 8 months ago by Glyph

Keywords: udp iocp removed

(Removing ad-hoc keywords, since keywords are for workflow)

comment:5 Changed 8 months ago by Glyph

Keywords: review removed
Owner: set to Xander Desai

I reviewed over on Github; just some minor feedback which we can merge after it gets addressed.

comment:6 Changed 6 months ago by Wim Lewis

I think the PR on github is good. I added a suggestion for a minor change.

Note: See TracTickets for help on using tickets.