Skip to content

Occasional InvalidStateError  #43

@vegeta1k95

Description

@vegeta1k95

If I put in a loop a function which creates a Thread which connects to proxy (one proxie at each iteration) and disconnects immediately, sometimes I get errors like this:

Exception in callback Future.set_result(True)
handle: <Handle Future.set_result(True) created at D:\!_Work\Python38\lib\site-packages\aiosocks\protocols.py:92>
source_traceback: Object created at (most recent call last):
  File "D:\!_Work\Python38\lib\concurrent\futures\thread.py", line 80, in _worker
    work_item.run()
  File "D:\!_Work\Python38\lib\concurrent\futures\thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "D:\!_Work\Python38\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "D:\!_Work\Python38\lib\asyncio\base_events.py", line 603, in run_until_complete
    self.run_forever()
  File "D:\!_Work\Python38\lib\asyncio\base_events.py", line 570, in run_forever
    self._run_once()
  File "D:\!_Work\Python38\lib\asyncio\base_events.py", line 1851, in _run_once
    handle._run()
  File "D:\!_Work\Python38\lib\asyncio\events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "D:\!_Work\Python38\lib\site-packages\aiosocks\protocols.py", line 92, in negotiate
    self._loop.call_soon(self._waiter.set_result, True)
Traceback (most recent call last):
  File "D:\!_Work\Python38\lib\asyncio\events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
asyncio.exceptions.InvalidStateError: invalid state

For some reason, _waiter is already cancelled when we are trying to set result to it, which lead to error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions