Skip to content

Better validate serve_listeners handling of weird edge cases #492

Open
@njsmith

Description

@njsmith

Looking at twisted/twisted#996 led me to investigate more the difference between EMFILE and WSAEMFILE... the latter is the special "winsockets" version of EMFILE, and apparently they are actually different:

In [2]: errno.EMFILE
Out[2]: 24

In [3]: errno.WSAEMFILE
Out[3]: 10024

And right now serve_listeners has special handling for EMFILE, but not WSAEMFILE... so it's probably broken.

We should:

  • Add the WSA variants to the list of errnos here:
    ACCEPT_CAPACITY_ERRNOS = {
    errno.EMFILE,
    errno.ENFILE,
    errno.ENOMEM,
    errno.ENOBUFS,
    }
  • Double-check if we need to modify the list in SocketListener:
    _ignorable_accept_errno_names = [
    # Linux can do this when the a connection is denied by the firewall
    "EPERM",
    # BSDs with an early close/reset
    "ECONNABORTED",
    # All the other miscellany noted above -- may not happen in practice, but
    # whatever.
    "EPROTO",
    "ENETDOWN",
    "ENOPROTOOPT",
    "EHOSTDOWN",
    "ENONET",
    "EHOSTUNREACH",
    "EOPNOTSUPP",
    "ENETUNREACH",
    "ENOSR",
    "ESOCKTNOSUPPORT",
    "EPROTONOSUPPORT",
    "ETIMEDOUT",
    "ECONNRESET",
    ]
  • Modify our EMFILE test so that it actually provokes a real EMFILE, instead of a fake one like we do now:
    async def raise_EMFILE():
    raise OSError(errno.EMFILE, "out of file descriptors")
    listener.accept_hook = raise_EMFILE

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions