aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/flow.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-12-29 22:44:18 +0100
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2017-12-29 22:56:29 +0100
commit62326227740d3808c0886ed381cb976a6b2f8b03 (patch)
treebb86ed2d55822470608568115ce41ce51c6edba8 /mitmproxy/flow.py
parent59c277effd016fdf771a65aaaa87526ff5fe869e (diff)
downloadmitmproxy-62326227740d3808c0886ed381cb976a6b2f8b03.tar.gz
mitmproxy-62326227740d3808c0886ed381cb976a6b2f8b03.tar.bz2
mitmproxy-62326227740d3808c0886ed381cb976a6b2f8b03.zip
fix Flow.kill behaviour
This now just sets a kill reply instead of committing directly. First, this seems like the more sane thing to do. Second, we have an iffy race condition where we call Reply.commit() before the addonmanager finishes its invocation, the proxy thread then progresses and sets a new flow.reply attribute, and the addonmanager then gets confused when finishing. This commit doesn't fix that, but mitigates it for Flow.kill which is now committed by the addonmanager.
Diffstat (limited to 'mitmproxy/flow.py')
-rw-r--r--mitmproxy/flow.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/mitmproxy/flow.py b/mitmproxy/flow.py
index 111566b8..944c032d 100644
--- a/mitmproxy/flow.py
+++ b/mitmproxy/flow.py
@@ -1,13 +1,12 @@
import time
+import typing # noqa
import uuid
-from mitmproxy import controller # noqa
-from mitmproxy import stateobject
from mitmproxy import connections
+from mitmproxy import controller, exceptions # noqa
+from mitmproxy import stateobject
from mitmproxy import version
-import typing # noqa
-
class Error(stateobject.StateObject):
@@ -145,7 +144,11 @@ class Flow(stateobject.StateObject):
@property
def killable(self):
- return self.reply and self.reply.state == "taken"
+ return (
+ self.reply and
+ self.reply.state in {"start", "taken"} and
+ self.reply.value != exceptions.Kill
+ )
def kill(self):
"""
@@ -153,13 +156,7 @@ class Flow(stateobject.StateObject):
"""
self.error = Error("Connection killed")
self.intercepted = False
-
- # reply.state should be "taken" here, or .take() will raise an
- # exception.
- if self.reply.state != "taken":
- self.reply.take()
self.reply.kill(force=True)
- self.reply.commit()
self.live = False
def intercept(self):