Opened 5 years ago

Last modified 4 years ago

#5377 defect new

twisted.internet.udp.Port is disconnected by _PollLikeMixin reactors when it gets connection refused

Reported by: zseil Owned by:
Priority: normal Milestone:
Component: core Keywords:
Cc: Branch:

Description (last modified by Itamar Turner-Trauring)

SelectReactor calls selectable.doRead() even when the selectable gets disconnected, which allows udp.Port.doRead() to call protocol.connectionRefused(). In constrast, PollReactor and other call selectable.connectionLost() directly in case of bare _POLL_DISCONNECTED event. See the attached test which hangs on Poll, Epoll and Gtk2 reactors but passes on Select reactor on Linux (Ubuntu Lucid).

Possibly the test is wrong, maybe udp.Port.doRead() should stop listening if recvfrom fails with ECONNREFUSED or ECONNRESET instead of calling protocol.connectionRefused().

Attachments (1)

poll-like-disconnect-test.patch (1.9 KB) - added by zseil 5 years ago.
failing (possibly incorect) test

Download all attachments as: .zip

Change History (5)

Changed 5 years ago by zseil

failing (possibly incorect) test

comment:1 Changed 5 years ago by Itamar Turner-Trauring

So it seems like what's happening is that if you get connection refused, poll() and friends consider this to be a disconnect? I suppose that kinda makes sense, and yes, that does seem like a bug in our current implementation.

The correct solution would be to have udp.Port.connectionLost have a special behavior where it doesn't actually disconnect if it's in connected mode, but rather calls connectionRefused instead. Possibly it should never disconnect when called. Besides the current attached test we'd want to make sure connectionRefused isn't called over and over and over again if this happens.

comment:2 Changed 5 years ago by Itamar Turner-Trauring

Description: modified (diff)
Summary: _PollLikeMixin should match the bahavior of SelectReactor in case of _POLL_DISCONNECTEDtwisted.internet.udp.Port is disconnected by _PollLikeMixin reactors when it gets connection refused

comment:3 Changed 5 years ago by Itamar Turner-Trauring

If Port.connectionLost is intended mostly for connectionRefused, this raises the question of when it should actually be disconnecting the port. My answer is "probably never" - given the connectionless nature of UDP, I'm not sure errors from datagramReceived or doRead really are grounds for disconnection. Even if they are, they should be distinguishable from connectionRefused situation by the error passed to Port.connectionLost.

comment:4 Changed 4 years ago by Richard Wall

This could be the same or related to #6467.

Note: See TracTickets for help on using tickets.