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

StreamWriter.drain() unreliably reports closed sockets #69627

Closed
sebastienbourdeauducq mannequin opened this issue Oct 19, 2015 · 5 comments
Closed

StreamWriter.drain() unreliably reports closed sockets #69627

sebastienbourdeauducq mannequin opened this issue Oct 19, 2015 · 5 comments
Assignees

Comments

@sebastienbourdeauducq
Copy link
Mannequin

sebastienbourdeauducq mannequin commented Oct 19, 2015

BPO 25441
Nosy @gvanrossum, @vstinner, @1st1

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 = 'https://github.com/gvanrossum'
closed_at = <Date 2015-10-19.19:02:16.849>
created_at = <Date 2015-10-19.14:12:09.958>
labels = ['expert-asyncio']
title = 'StreamWriter.drain() unreliably reports closed sockets'
updated_at = <Date 2015-10-19.19:10:21.647>
user = 'https://bugs.python.org/sebastienbourdeauducq'

bugs.python.org fields:

activity = <Date 2015-10-19.19:10:21.647>
actor = 'python-dev'
assignee = 'gvanrossum'
closed = True
closed_date = <Date 2015-10-19.19:02:16.849>
closer = 'gvanrossum'
components = ['asyncio']
creation = <Date 2015-10-19.14:12:09.958>
creator = 'sebastien.bourdeauducq'
dependencies = []
files = []
hgrepos = []
issue_num = 25441
keywords = []
message_count = 5.0
messages = ['253181', '253182', '253184', '253186', '253187']
nosy_count = 5.0
nosy_names = ['gvanrossum', 'vstinner', 'python-dev', 'yselivanov', 'sebastien.bourdeauducq']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue25441'
versions = ['Python 3.4', 'Python 3.5', 'Python 3.6']

@sebastienbourdeauducq
Copy link
Mannequin Author

sebastienbourdeauducq mannequin commented Oct 19, 2015

  1. Open a listening socket:
    $ nc6 -l -p 1066

  2. Run the following (tested here on Linux):
    import asyncio

async def bug():
    reader, writer = await asyncio.open_connection("::1", "1066")
    while True:
        writer.write("foo\n".encode())
        await writer.drain()
        # Uncommenting this makes drain() raise BrokenPipeError
        # when the server closes the connection.
        #await asyncio.sleep(0.1)

loop = asyncio.get_event_loop()
loop.run_until_complete(bug())
  1. Terminate netcat with Ctrl-C. The program will go on a endless loop of "socket.send() raised exception." as writer.drain() fails to raise an exception to report the closed connection. Reducing the output rate of the program by using asyncio.sleep causes writer.drain() to raise BrokenPipeError (and shouldn't it be ConnectionResetError?)

@gvanrossum
Copy link
Member

See also this upstream git issue: python/asyncio#263. Let me know whether the patch suggested there works for you, and I'll prioritize getting it checked in. (Help would also be appreciated, e.g. in the form of a unittest.)

@sebastienbourdeauducq
Copy link
Mannequin Author

sebastienbourdeauducq mannequin commented Oct 19, 2015

Yes, this patch fixes the problem (in both this example and my real application). Thanks!

@gvanrossum
Copy link
Member

Fixed by 17f76258d11d, d30fbc55194d and 08adb4056b5f.

@gvanrossum gvanrossum self-assigned this Oct 19, 2015
@python-dev
Copy link
Mannequin

python-dev mannequin commented Oct 19, 2015

New changeset 17f76258d11d by Guido van Rossum in branch '3.4':
Issue bpo-25441: asyncio: Raise error from drain() when socket is closed.
https://hg.python.org/cpython/rev/17f76258d11d

New changeset d30fbc55194d by Guido van Rossum in branch '3.5':
Issue bpo-25441: asyncio: Raise error from drain() when socket is closed. (Merge 3.4->3.5)
https://hg.python.org/cpython/rev/d30fbc55194d

New changeset 08adb4056b5f by Guido van Rossum in branch 'default':
Issue bpo-25441: asyncio: Raise error from drain() when socket is closed. (Merge 3.5->3.6)
https://hg.python.org/cpython/rev/08adb4056b5f

@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
Projects
None yet
Development

No branches or pull requests

1 participant