← index #98Issue #6576
Related · high · value 0.982
QUERY · ISSUE

[uasyncio] Trying to call aclose() twice on streams with the same underlying socket leads to exception

openby danniopened 2016-08-30updated 2017-03-12
reader, writer = await asyncio.open_connection(hostname, port)
# sending and receiving
await reader.aclose()
await writer.aclose()
Traceback (most recent call last):
  File "client.py", line 28, in <module>
  File "/Users/danni/.micropython/lib/uasyncio/core.py", line 112, in run_until_complete
  File "/Users/danni/.micropython/lib/uasyncio/core.py", line 104, in run_forever
  File "/Users/danni/.micropython/lib/uasyncio/core.py", line 89, in run_forever
  File "/Users/danni/.micropython/lib/uasyncio/__init__.py", line 28, in remove_reader
KeyError: <value>
2 comments
dxxb · 2016-08-30

@danni, I think the issue's title is misleading. The file descriptor is removed but aclose() will try to remove it a second time and del self.objmap[fd] will raise a KeyError here https://github.com/micropython/micropython-lib/blob/master/uasyncio/uasyncio/init.py#L28.
Probably all instances of del self.objmap[fd] should become self.objmap.pop(fd, None)

pfalcon · 2017-03-12

So, this wasn't actionated, because I'm not sure what's the best way to deal with it. The idea of uasyncio is to stay lead and mean, and while there're explicit read and write streams, it's still a public API fact that they refer to the same underlying object, and it doesn't make sense to close it twice. A writer is the default thing to close (because that's the way to signal the other side of the connection that you've done with sending data; closing reader is the way to abruptly abort a connection). However, the code above - closing reader, then writer - should work with the current uasyncio version, but not vice versa. I'm not sure that requires fixing, because again, the idea is that it shouldn't be closed twice.

Overall, this will likely need to wait until until uselect module will get support to store "callback data" on its side.

CANDIDATE · ISSUE

Fatal Uasyncio/Uart Stream Lifecycle Bug (STM32)

closedby gtomassiopened 2020-10-28updated 2021-05-13
extmod

When calling aclose (maps to Stream.wait_closed) on the new implementation of Stream, something goes awry in the stream read process and begins raising exceptions. This will likely have a fatal impact on any projects using UARTs with any life cycle when migrating to uasyncio v3.

After calling aclose the following stack trace is seen:

AssertionError:
  ...
  File "uasyncio/stream.py", line 30, in read
  File "uasyncio/core.py", line 94, in queue_read
  File "uasyncio/core.py", line 82, in _enqueue

It keeps repeating rapidly forever..

Steps to reproduce:

  1. Open a UART connection using the stream reader 'streamReader = asyncio.StreamReader(uart)'
  2. Listen to the stream reader using streamReader.read(n)
  3. Close the stream reader
  4. Not sure if this is required, but open a new stream reader on the same UART again

Notes:

  • The read is not being "released" when closing the stream reader, and thus tries to continue to read on a closed stream reader. yield IOReadDone(self.polls) was in the v2 implementation and no equivalent operation exists in the v3.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied