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:
Maximilian Hils 2024-04-24 14:14:54 +02:00 committed by GitHub
parent b2298d7e99
commit b5574fb298
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 9 deletions

View File

@ -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

View File

@ -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):

View File

@ -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))