Skip to content

Commit 8d81b14

Browse files
--inactive-conn-cleanup-timeout (#1504)
* `--inactive-conn-cleanup-timeout` * Specify default in docs * Update README * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Clarify usecase is comments * Lint --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 050ac1c commit 8d81b14

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,6 +2619,7 @@ usage: -m [-h] [--tunnel-hostname TUNNEL_HOSTNAME] [--tunnel-port TUNNEL_PORT]
26192619
[--tunnel-ssh-key-passphrase TUNNEL_SSH_KEY_PASSPHRASE]
26202620
[--tunnel-remote-port TUNNEL_REMOTE_PORT] [--threadless]
26212621
[--threaded] [--num-workers NUM_WORKERS] [--enable-events]
2622+
[--inactive-conn-cleanup-timeout INACTIVE_CONN_CLEANUP_TIMEOUT]
26222623
[--enable-proxy-protocol] [--enable-conn-pool] [--key-file KEY_FILE]
26232624
[--cert-file CERT_FILE] [--client-recvbuf-size CLIENT_RECVBUF_SIZE]
26242625
[--server-recvbuf-size SERVER_RECVBUF_SIZE]
@@ -2682,6 +2683,16 @@ options:
26822683
--enable-events Default: False. Enables core to dispatch lifecycle
26832684
events. Plugins can be used to subscribe for core
26842685
events.
2686+
--inactive-conn-cleanup-timeout INACTIVE_CONN_CLEANUP_TIMEOUT
2687+
Time after which inactive works must be cleaned up.
2688+
Increase this value if your backend services are slow
2689+
to response or when proxy.py is handling a high
2690+
volume. When running proxy.py on Google Cloud (GCP)
2691+
you may see 'backend_connection_closed_before_data_sen
2692+
t_to_client', with curl clients you may see 'Empty
2693+
reply from server' error when '--inactive-conn-
2694+
cleanup-timeout' value is low for your use-case.
2695+
Default 1 seconds
26852696
--enable-proxy-protocol
26862697
Default: False. If used, will enable proxy protocol.
26872698
Only version 1 is currently supported.

proxy/core/work/threadless.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
cast,
2121
)
2222

23+
from ...common.flag import flags as proxy_flags
2324
from ...common.types import Readables, Writables, SelectableEvents
2425
from ...common.logger import Logger
2526
from ...common.constants import (
@@ -37,6 +38,20 @@
3738
logger = logging.getLogger(__name__)
3839

3940

41+
proxy_flags.add_argument(
42+
'--inactive-conn-cleanup-timeout',
43+
default=DEFAULT_INACTIVE_CONN_CLEANUP_TIMEOUT,
44+
help='Time after which inactive works must be cleaned up. '
45+
+ 'Increase this value if your backend services are slow to response '
46+
+ 'or when proxy.py is handling a high volume. When running proxy.py on Google Cloud (GCP) '
47+
+ "you may see 'backend_connection_closed_before_data_sent_to_client', with curl clients "
48+
+ "you may see 'Empty reply from server' error when '--inactive-conn-cleanup-timeout' "
49+
+ 'value is low for your use-case. Default {0} seconds'.format(
50+
DEFAULT_INACTIVE_CONN_CLEANUP_TIMEOUT,
51+
),
52+
)
53+
54+
4055
class Threadless(ABC, Generic[T]):
4156
"""Work executor base class.
4257
@@ -87,7 +102,7 @@ def __init__(
87102
SelectableEvents,
88103
] = {}
89104
self.wait_timeout: float = DEFAULT_WAIT_FOR_TASKS_TIMEOUT
90-
self.cleanup_inactive_timeout: float = DEFAULT_INACTIVE_CONN_CLEANUP_TIMEOUT
105+
self.cleanup_inactive_timeout: float = self.flags.inactive_conn_cleanup_timeout
91106
self._total: int = 0
92107
# When put at the top, causes circular import error
93108
# since integrated ssh tunnel was introduced.

0 commit comments

Comments
 (0)