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

KeyError: <aiohttp.connector._TransportPlaceholder> #2193

Closed
rndusr opened this issue Aug 12, 2017 · 4 comments
Closed

KeyError: <aiohttp.connector._TransportPlaceholder> #2193

rndusr opened this issue Aug 12, 2017 · 4 comments
Assignees
Labels
Milestone

Comments

@rndusr
Copy link

rndusr commented Aug 12, 2017

I'm not sure if this is a bug in aiohttp, but if it's a bug in my code, this error doesn't tell my anything:

  File "/home/ich/code/stig/stig/client/aiotransmission/rpc.py", line 328, in __post
    response = await self.__session.post(repr(self.__url), data=data, headers=self.__headers)
  File "/home/ich/code/aiohttp/aiohttp/helpers.py", line 102, in __await__
    ret = yield from self._coro
  File "/home/ich/code/aiohttp/aiohttp/client.py", line 233, in _request
    conn = yield from self._connector.connect(req)
  File "/home/ich/code/aiohttp/aiohttp/connector.py", line 386, in connect
    self._acquired.remove(placeholder)
KeyError: <aiohttp.connector._TransportPlaceholder object at 0x7f270bc78c88>

So, placeholder is added to self._acquired (line 379) and then removed again (line 386), but inbetween it has already been removed, hence the KeyError.

The culprit is self._create_connection(req) (line 382), and eventually self._loop.create_connection() (line 732), and then I'm losing track.

Anyway, a simple if placeholder in self._acquired: inserted in line 386 seems to fix the issue for me. Or it could be something wrong with my code, but then I still have no idea what it is I'm doing wrong. I'd appreciate any pointers what could cause this.

I can reproduce, but unfortunately not with simple, sharable code.

@rndusr
Copy link
Author

rndusr commented Aug 13, 2017

After some more investigating, I think the issue is that I somehow close() my ClientSession before _create_connection() is finished. close() calls self._acquired.clear() (line 328) and that explains the KeyError when placeholder is to be removed from self._acquired after _create_connection() finished.

I've fixed my code, but it seems to me that this is still an issue in aiohttp. I should either get a more helpful exception or placeholder should be removed with the discard() method, which does nothing if placeholder isn't in self._acquired.

@fafhrd91
Copy link
Member

fixed by 941a218

fafhrd91 added a commit that referenced this issue Sep 20, 2017
@fafhrd91
Copy link
Member

e404760

fafhrd91 added a commit that referenced this issue Sep 21, 2017
@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants