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

asyncore does not check for POLLERR and POLLHUP if neither readable nor writable #55476

Closed
socketpair mannequin opened this issue Feb 21, 2011 · 3 comments
Closed

asyncore does not check for POLLERR and POLLHUP if neither readable nor writable #55476

socketpair mannequin opened this issue Feb 21, 2011 · 3 comments
Labels
stdlib Python modules in the Lib dir topic-IO type-bug An unexpected behavior, bug, or error

Comments

@socketpair
Copy link
Mannequin

socketpair mannequin commented Feb 21, 2011

BPO 11267
Nosy @vstinner, @giampaolo, @socketpair

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 2014-08-27.16:29:53.358>
created_at = <Date 2011-02-21.05:54:31.497>
labels = ['invalid', 'type-bug', 'library', 'expert-IO']
title = 'asyncore does not check for POLLERR and POLLHUP if neither readable nor writable'
updated_at = <Date 2014-08-27.16:29:53.355>
user = 'https://github.com/socketpair'

bugs.python.org fields:

activity = <Date 2014-08-27.16:29:53.355>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2014-08-27.16:29:53.358>
closer = 'vstinner'
components = ['Library (Lib)', 'IO']
creation = <Date 2011-02-21.05:54:31.497>
creator = 'socketpair'
dependencies = []
files = []
hgrepos = []
issue_num = 11267
keywords = []
message_count = 3.0
messages = ['128941', '220903', '225999']
nosy_count = 4.0
nosy_names = ['vstinner', 'giampaolo.rodola', 'BreamoreBoy', 'socketpair']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue11267'
versions = ['Python 3.1', 'Python 3.4', 'Python 3.5']

@socketpair
Copy link
Mannequin Author

socketpair mannequin commented Feb 21, 2011

asyncore.py: poll2() :
--------------------

if flags:
    # Only check for exceptions if object was either readable
    # or writable.
    flags |= select.POLLERR | select.POLLHUP | select.POLLNVAL
    pollster.register(fd, flags)

This is unexpected behaviour. Why descriptor does not get polled if neither read nor write selected ? So I can not track dropping of connection if I do not want neither read nor write. I think "if flags:" should be removed.

@socketpair socketpair mannequin added stdlib Python modules in the Lib dir topic-IO type-bug An unexpected behavior, bug, or error labels Feb 21, 2011
@BreamoreBoy
Copy link
Mannequin

BreamoreBoy mannequin commented Jun 17, 2014

I'm assuming that any work on this is unlikely as asyncore is deprecated in favour of asyncio.

@vstinner
Copy link
Member

Why descriptor does not get polled if neither read nor write selected ?

IMO it's a deliberate design choice, made for performances.

In the asyncio module, the high-level StreamReader API stops listening to read even if the buffer is too large (if we received more than limit*2 bytes, where limit is 64 KB by default). We listen again when the application reads enough data from the buffer.

When we stop listening to read event (and we don't listen to write events neither), we ignore completly the socket. So if the socket is closed, we are not notified immediatly. IMO it's a design choice for efficency. It's more efficient to ignore temporarily the socket while the application is busy, than notifying immediatly that the connection was closed.

In my test, I still got some bytes with socket.recv() even after the connection was already closed by the peer.

Pseudo-code:

  • client: connect
  • client: recv(10): get some bytes
  • server: close the connection
  • client: recv(10): get more bytes (even if the connection was already closed)
  • client: notified that the connection was closed

I don't think that asyncore nor asyncio should be modified to be notified immediatly that a connection was closed, so I close the issue.

Thanks for your report, it was an interesting question :-)

@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
stdlib Python modules in the Lib dir topic-IO type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant