diff --git a/mitmproxy/proxy/layers/tls.py b/mitmproxy/proxy/layers/tls.py index d8a33ac9c..cdc3bdec0 100644 --- a/mitmproxy/proxy/layers/tls.py +++ b/mitmproxy/proxy/layers/tls.py @@ -254,7 +254,11 @@ class _TLSLayer(tunnel.TunnelLayer): yield from super().receive_close() def send_data(self, data: bytes) -> layer.CommandGenerator[None]: - self.tls.sendall(data) + try: + self.tls.sendall(data) + except SSL.ZeroReturnError: + # The other peer may still be trying to send data over, which we discard here. + pass yield from self.tls_interact() def send_close(self, half_close: bool) -> layer.CommandGenerator[None]: diff --git a/mitmproxy/proxy/tunnel.py b/mitmproxy/proxy/tunnel.py index 14c54c6f5..bd622aeb9 100644 --- a/mitmproxy/proxy/tunnel.py +++ b/mitmproxy/proxy/tunnel.py @@ -75,7 +75,7 @@ class TunnelLayer(layer.Layer): if self.tunnel_state is TunnelState.OPEN: yield from self.receive_close() elif self.tunnel_state is TunnelState.ESTABLISHING: - err = "connection closed without notice" + err = "connection closed" yield from self.on_handshake_error(err) yield from self._handshake_finished(err) self.tunnel_state = TunnelState.CLOSED diff --git a/test/mitmproxy/proxy/layers/test_tls.py b/test/mitmproxy/proxy/layers/test_tls.py index f158bb53d..28b8625c6 100644 --- a/test/mitmproxy/proxy/layers/test_tls.py +++ b/test/mitmproxy/proxy/layers/test_tls.py @@ -509,6 +509,6 @@ class TestClientTLS: << commands.SendData(tctx.client, tutils.Placeholder()) >> events.ConnectionClosed(tctx.client) << commands.Log("Client TLS handshake failed. The client may not trust the proxy's certificate " - "for wrong.host.mitmproxy.org (connection closed without notice)", "warn") + "for wrong.host.mitmproxy.org (connection closed)", "warn") << commands.CloseConnection(tctx.client) ) diff --git a/test/mitmproxy/proxy/test_tunnel.py b/test/mitmproxy/proxy/test_tunnel.py index 6f852ce68..68baad6db 100644 --- a/test/mitmproxy/proxy/test_tunnel.py +++ b/test/mitmproxy/proxy/test_tunnel.py @@ -245,7 +245,7 @@ def test_disconnect_during_handshake_command(tctx: Context, disconnect): >> ConnectionClosed(tctx.client) >> ConnectionClosed(server) # proxyserver will cancel all other connections as well. << CloseConnection(server) - << Log("Opened: err='connection closed without notice'. Server state: CLOSED") + << Log("Opened: err='connection closed'. Server state: CLOSED") << Log("Got client close.") << CloseConnection(tctx.client) ) @@ -254,7 +254,7 @@ def test_disconnect_during_handshake_command(tctx: Context, disconnect): playbook >> ConnectionClosed(server) << CloseConnection(server) - << Log("Opened: err='connection closed without notice'. Server state: CLOSED") + << Log("Opened: err='connection closed'. Server state: CLOSED") )