← index #98Issue #402
Related · medium · value 1.266
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

Uasyncio Uart Stream Close Bug

closedby gtomassiopened 2020-10-28updated 2020-10-28

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.

After calling aclose the following stack trace is seen:

  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

Steps to reproduce:

  1. Open a UART connection using the stream reader 'streamReader = asyncio.StreamReader(uart)'
  2. Close the stream reader
  3. Not sure if this is required, but open a new stream reader on the same UART again
1 comment
gtomassi · 2020-10-28

Moving to https://github.com/micropython/micropython/issues/6576

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