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

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

Open
danni opened this issue Aug 30, 2016 · 2 comments

Comments

@danni
Copy link

danni commented Aug 30, 2016

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>
@dxxb
Copy link
Contributor

dxxb commented Aug 30, 2016

@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 pfalcon changed the title [uasyncio] aclose() doesn't remove reader/writer from event loop [uasyncio] Trying to call aclose() twice on the same underlying socket leads to exception Mar 12, 2017
@pfalcon pfalcon changed the title [uasyncio] Trying to call aclose() twice on the same underlying socket leads to exception [uasyncio] Trying to call aclose() twice on streams with the same underlying socket leads to exception Mar 12, 2017
@pfalcon
Copy link
Contributor

pfalcon commented Mar 12, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants