Fix program exit when `n` is passed (#6819)
* fix program exit when `n` is passed fix #6818 * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
b2298d7e99
commit
b5574fb298
|
@ -9,6 +9,8 @@
|
|||
|
||||
* Release tags are now prefixed with `v` again to follow SemVer convention.
|
||||
([#6810](https://github.com/mitmproxy/mitmproxy/pull/6810), @mhils)
|
||||
* Fix a bug where mitmproxy would not exit when `-n` is passed.
|
||||
([#6819](https://github.com/mitmproxy/mitmproxy/pull/6819), @mhils)
|
||||
|
||||
|
||||
## 17 April 2024: mitmproxy 10.3.0
|
||||
|
|
|
@ -71,8 +71,6 @@ class ReadFile:
|
|||
await self.load_flows_from_path(rfile)
|
||||
except exceptions.FlowReadException as e:
|
||||
logger.exception(f"Failed to read {ctx.options.rfile}: {e}")
|
||||
finally:
|
||||
self._read_task = None
|
||||
|
||||
def running(self):
|
||||
if ctx.options.rfile:
|
||||
|
@ -80,7 +78,7 @@ class ReadFile:
|
|||
|
||||
@command.command("readfile.reading")
|
||||
def reading(self) -> bool:
|
||||
return bool(self._read_task)
|
||||
return bool(self._read_task and not self._read_task.done())
|
||||
|
||||
|
||||
class ReadFileStdin(ReadFile):
|
||||
|
|
|
@ -54,13 +54,21 @@ class TestReadFile:
|
|||
|
||||
tf = tmpdir.join("tfile")
|
||||
|
||||
with mock.patch("mitmproxy.master.Master.load_flow") as mck:
|
||||
tf.write(data.getvalue())
|
||||
tctx.configure(rf, rfile=str(tf), readfile_filter=".*")
|
||||
mck.assert_not_awaited()
|
||||
rf.running()
|
||||
load_called = asyncio.Event()
|
||||
|
||||
async def load_flow(*_, **__):
|
||||
load_called.set()
|
||||
|
||||
tctx.master.load_flow = load_flow
|
||||
|
||||
tf.write(data.getvalue())
|
||||
tctx.configure(rf, rfile=str(tf), readfile_filter=".*")
|
||||
assert not load_called.is_set()
|
||||
rf.running()
|
||||
await load_called.wait()
|
||||
|
||||
while rf.reading():
|
||||
await asyncio.sleep(0)
|
||||
mck.assert_awaited()
|
||||
|
||||
tf.write(corrupt_data.getvalue())
|
||||
tctx.configure(rf, rfile=str(tf))
|
||||
|
|
Loading…
Reference in New Issue