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

Issue with IOCPReactor's handling of WSAECONNREFUSED #10052

Closed
twisted-trac opened this issue Nov 12, 2020 · 7 comments
Closed

Issue with IOCPReactor's handling of WSAECONNREFUSED #10052

twisted-trac opened this issue Nov 12, 2020 · 7 comments

Comments

@twisted-trac
Copy link

mbish's avatar @mbish reported
Trac ID trac#10052
Type defect
Created 2020-11-12 22:24:23Z

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

Searchable metadata
trac-id__10052 10052
type__defect defect
reporter__mbish mbish
priority__normal normal
milestone__None None
branch__ 
branch_author__ 
status__closed closed
resolution__fixed fixed
component__core core
keywords__None None
time__1605219863017012 1605219863017012
changetime__1655064570840490 1655064570840490
version__None None
owner__mbish mbish
cc__xdesai
@twisted-trac
Copy link
Author

xdesai's avatar @xdesai commented

Pull request that fixes this bug is here: #1482

@twisted-trac
Copy link
Author

xdesai's avatar @xdesai commented

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

@twisted-trac
Copy link
Author

glyph's avatar @glyph commented

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

@twisted-trac
Copy link
Author

glyph's avatar @glyph set owner to @xdesai

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

@twisted-trac
Copy link
Author

wiml's avatar @wiml commented

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

@twisted-trac
Copy link
Author

mbish's avatar @mbish set owner to @mbish
@mbish set status to assigned

This change has been approved here #1482 (review) but not yet merged into trunk.

@twisted-trac
Copy link
Author

twm's avatar @twm set status to closed

Merged in 4532762

Thanks for your contribution and patience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant