Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

## Unreleased: mitmproxy next

- Make TCP inactivity timeout configurable through a new `tcp_timeout` option (default: 600 seconds).
Previously, the timeout was hardcoded to 10 minutes for all TCP connections.
([#7909](https://github.com/mitmproxy/mitmproxy/pull/7909), @keshavkrishnadav)

## 15 October 2025: mitmproxy 12.2.0

Expand Down
8 changes: 8 additions & 0 deletions mitmproxy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,13 @@ def __init__(self, **kwargs) -> None:
None,
"Path to a .proto file that's used to resolve Protobuf field names when pretty-printing.",
)
self.add_option(
"tcp_timeout",
int,
600,
"""
Timeout in seconds for inactive TCP connections. Connections will be closed after this period of inactivity.
""",
)

self.update(**kwargs)
3 changes: 1 addition & 2 deletions mitmproxy/proxy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

logger = logging.getLogger(__name__)

TCP_TIMEOUT = 60 * 10
UDP_TIMEOUT = 20


Expand Down Expand Up @@ -115,7 +114,7 @@ def __init__(self, context: Context) -> None:
# on protocols that start with a server greeting.
self.layer = layer.NextLayer(context, ask_on_start=True)
if self.client.transport_protocol == "tcp":
timeout = TCP_TIMEOUT
timeout = context.options.tcp_timeout
else:
timeout = UDP_TIMEOUT
self.timeout_watchdog = TimeoutWatchdog(timeout, self.on_timeout)
Expand Down
3 changes: 3 additions & 0 deletions mitmproxy/tools/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def common_options(parser, opts):
group = parser.add_argument_group("Modify Headers")
opts.make_parser(group, "modify_headers", metavar="PATTERN", short="H")

# TCP Options
opts.make_parser(group, "tcp_timeout", metavar="SECONDS")


def mitmproxy(opts):
parser = argparse.ArgumentParser(usage="%(prog)s [options]")
Expand Down
10 changes: 10 additions & 0 deletions test/mitmproxy/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@

def test_simple():
assert options.Options()


def test_tcp_timeout_default():
opts = options.Options()
assert opts.tcp_timeout == 600


def test_tcp_timeout_settable():
opts = options.Options(tcp_timeout=123)
assert opts.tcp_timeout == 123
12 changes: 6 additions & 6 deletions web/gen/options_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@


def _ts_type(t):
if t is bool:
if t == bool: # noqa: E721
return "boolean"
if t is str:
if t == str: # noqa: E721
return "string"
if t is int:
if t == int: # noqa: E721
return "number"
if t == Sequence[str]:
if t == Sequence[str]: # noqa: E721
return "string[]"
if t == str | None:
if t == str | None: # noqa: E721
return "string | undefined"
if t == int | None:
if t == int | None: # noqa: E721
return "number | undefined"
raise RuntimeError(t)

Expand Down
2 changes: 2 additions & 0 deletions web/src/js/ducks/_options_gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface OptionsState {
stream_large_bodies: string | undefined;
strip_ech: boolean;
tcp_hosts: string[];
tcp_timeout: number;
termlog_verbosity: string;
tls_ecdh_curve_client: string | undefined;
tls_ecdh_curve_server: string | undefined;
Expand Down Expand Up @@ -185,6 +186,7 @@ export const defaultState: OptionsState = {
stream_large_bodies: undefined,
strip_ech: true,
tcp_hosts: [],
tcp_timeout: 600,
termlog_verbosity: "info",
tls_ecdh_curve_client: undefined,
tls_ecdh_curve_server: undefined,
Expand Down
Loading