goodboy / tractor

A distributed, structured concurrent runtime for Python (and friends)
GNU Affero General Public License v3.0
270 stars 12 forks source link

Need to handle a `KeyError` in `_debug._hijack_stdin_for_child` #310

Closed goodboy closed 2 years ago

goodboy commented 2 years ago

This is probably yet another edge case to be included in #165

Traceback (most recent call last):
  File "/home/goodboy/repos/tractor/tractor/_streaming.py", line 619, in open_stream
    yield stream
  File "/home/goodboy/repos/tractor/tractor/_debug.py", line 280, in _hijack_stdin_for_child
    assert await stream.receive() == 'pdb_unlock'
  File "/home/goodboy/repos/tractor/tractor/_streaming.py", line 104, in receive
    msg = await self._rx_chan.receive()
  File "/home/goodboy/repos/piker/310/lib/python3.10/site-packages/trio/_channel.py", line 314, in receive
    return await trio.lowlevel.wait_task_rescheduled(abort_fn)
  File "/home/goodboy/repos/piker/310/lib/python3.10/site-packages/trio/_core/_traps.py", line 166, in wait_task_rescheduled
    return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()
  File "/home/goodboy/repos/piker/310/lib/python3.10/site-packages/outcome/_impl.py", line 138, in unwrap
    raise captured_error
trio.ClosedResourceError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/goodboy/repos/tractor/tractor/_debug.py", line 279, in _hijack_stdin_for_child
    async with ctx.open_stream() as stream:
  File "/usr/lib/python3.10/contextlib.py", line 217, in __aexit__
    await self.gen.athrow(typ, value, traceback)
  File "/home/goodboy/repos/tractor/tractor/_streaming.py", line 628, in open_stream
    self._portal._streams.remove(stream)
KeyError: <tractor._streaming.MsgStream object at 0x7f8298dbe5f0>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/goodboy/repos/tractor/tractor/_debug.py", line 299, in _hijack_stdin_for_child
    lock.release()
  File "/home/goodboy/repos/piker/310/lib/python3.10/site-packages/trio/_core/_ki.py", line 159, in wrapper
    return fn(*args, **kwargs)
  File "/home/goodboy/repos/piker/310/lib/python3.10/site-packages/trio/_sync.py", line 556, in release
    raise RuntimeError("can't release a Lock you don't own")
RuntimeError: can't release a Lock you don't own
goodboy commented 2 years ago

Pretty sure this is now addressed in https://github.com/goodboy/tractor/pull/165/commits/71e779dca3ac8f9a509faf29b8c133446ef32244 but not sure exactly how to test for it?

goodboy commented 2 years ago

Marking resolved for now since it hasn't be reported since that patch.