diff --git a/mitmproxy/proxy/layers/modes.py b/mitmproxy/proxy/layers/modes.py index 299792107..501b14697 100644 --- a/mitmproxy/proxy/layers/modes.py +++ b/mitmproxy/proxy/layers/modes.py @@ -26,10 +26,10 @@ class DestinationKnown(layer.Layer, metaclass=ABCMeta): if self.context.options.connection_strategy == "eager": err = yield commands.OpenConnection(self.context.server) if err: - self._handle_event = self.done + self._handle_event = self.done # type: ignore return err - self._handle_event = self.child_layer.handle_event + self._handle_event = self.child_layer.handle_event # type: ignore yield from self.child_layer.handle_event(events.Start()) return None diff --git a/test/mitmproxy/proxy/layers/test_modes.py b/test/mitmproxy/proxy/layers/test_modes.py index a3db009d0..346590878 100644 --- a/test/mitmproxy/proxy/layers/test_modes.py +++ b/test/mitmproxy/proxy/layers/test_modes.py @@ -276,6 +276,22 @@ def test_reverse_eager_connect_failure(tctx: Context): ) +def test_transparent_eager_connect_failure(tctx: Context, monkeypatch): + """Test that we recover from a transparent mode resolve error.""" + tctx.options.connection_strategy = "eager" + monkeypatch.setattr(platform, "original_addr", lambda sock: ("address", 22)) + + assert ( + Playbook(modes.TransparentProxy(tctx), logs=True) + << GetSocket(tctx.client) + >> reply(object()) + << OpenConnection(tctx.server) + >> reply("something something") + << CloseConnection(tctx.client) + >> ConnectionClosed(tctx.client) + ) + + CLIENT_HELLO = b"\x05\x01\x00" SERVER_HELLO = b"\x05\x00"