-
Notifications
You must be signed in to change notification settings - Fork 12
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
detect closed StreamWriter/StreamReader not working #120
Comments
this one connecting to google works import sys
import asyncio
import logging
# using python3.6
logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.DEBUG)
async def connect():
reader, writer = await asyncio.open_connection(host="google.com", port=80)
writer.transport.set_write_buffer_limits(2)
return reader, writer
async def main():
_, writer = await connect()
while True:
# https://github.com/aio-libs/aiohttp/issues/2499
if writer.transport is None or writer.transport.is_closing():
# this should detect lost connection but it doesn't
raise ConnectionResetError("Cannot write to closing transport")
print("about to write")
writer.write(b"SomeMessage")
await writer.drain()
print("written")
await asyncio.sleep(4)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
about to write
written
about to write
written
about to write
written
about to write
written
about to write
written
about to write
written
_read_ready called
self.max_size: 262144
self._conn_lost: 0
[Errno 60] Operation timed out
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/selector_events.py", line 718, in _read_ready
data = self._sock.recv(self.max_size)
TimeoutError: [Errno 60] Operation timed out
Fatal read error on socket transport
protocol: <asyncio.streams.StreamReaderProtocol object at 0x103d16668>
transport: <_SelectorSocketTransport fd=9 read=polling write=<idle, bufsize=0>> |
However the following works okay: import asyncio
async def connect():
reader, writer = await asyncio.open_connection(host="127.0.0.1", port=8000)
return reader, writer
async def main():
_, writer = await connect()
while True:
# https://github.com/aio-libs/aiohttp/issues/2499
if writer.transport is None or writer.transport.is_closing():
# this should detect lost connection but it doesn't
raise ConnectionResetError("Cannot write to closing transport")
print("about to write")
writer.write(b"SomeMessage")
await writer.drain()
print("written")
await asyncio.sleep(1)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
about to write
written
about to write
written
about to write
written
about to write
written
about to write
written
about to write
Traceback (most recent call last):
File "cool.py", line 26, in <module>
loop.run_until_complete(main())
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
return future.result()
File "cool.py", line 19, in main
await writer.drain()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/streams.py", line 337, in drain
yield from self._protocol._drain_helper()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/streams.py", line 211, in _drain_helper
raise ConnectionResetError("Connection lost")
ConnectionResetError: Connection lost |
I'm beginning to supect that the difference between the example above that works(using SimpleHTTPServer) and the ones that do not is that those that do not are talking to a server running in docker. |
for the docker examples, if you restart docker itself; I'm able to get a ConnectionResetError |
What: - Introduce a configurable timeout when trying to connect to SMSC - Try and detect when the connection to SMSC is disconnected and attempt to re-connect & re-bind - bugfix; `asyncio.streams.StreamWriter.drain` should not be called concurrently by multiple coroutines[1] - when shutting down, `naz` now tries to make sure that write buffers are properly flushed[2][3] Why: - Make `naz` more failure tolerant - Fixes: #67 - Fixes: #114 - Fixes: #116 - Fixes: #117 - Fixes: #120 References: 1. https://bugs.python.org/issue29930 2. https://vorpus.org/blog/some-thoughts-on-asynchronous-api-design-in-a-post-asyncawait-world/ 3. aio-libs/aiohttp#1369
127.0.0.1:2775
127.0.0.1:2775
writer.transport.is_closing()
is supposed to tell us when/if the connection is broken but it does not.The text was updated successfully, but these errors were encountered: