diff --git a/README.md b/README.md index 68061779..e176ee51 100644 --- a/README.md +++ b/README.md @@ -2619,6 +2619,7 @@ usage: -m [-h] [--tunnel-hostname TUNNEL_HOSTNAME] [--tunnel-port TUNNEL_PORT] [--tunnel-ssh-key-passphrase TUNNEL_SSH_KEY_PASSPHRASE] [--tunnel-remote-port TUNNEL_REMOTE_PORT] [--threadless] [--threaded] [--num-workers NUM_WORKERS] [--enable-events] + [--inactive-conn-cleanup-timeout INACTIVE_CONN_CLEANUP_TIMEOUT] [--enable-proxy-protocol] [--enable-conn-pool] [--key-file KEY_FILE] [--cert-file CERT_FILE] [--client-recvbuf-size CLIENT_RECVBUF_SIZE] [--server-recvbuf-size SERVER_RECVBUF_SIZE] @@ -2682,6 +2683,16 @@ options: --enable-events Default: False. Enables core to dispatch lifecycle events. Plugins can be used to subscribe for core events. + --inactive-conn-cleanup-timeout INACTIVE_CONN_CLEANUP_TIMEOUT + Time after which inactive works must be cleaned up. + Increase this value if your backend services are slow + to response or when proxy.py is handling a high + volume. When running proxy.py on Google Cloud (GCP) + you may see 'backend_connection_closed_before_data_sen + t_to_client', with curl clients you may see 'Empty + reply from server' error when '--inactive-conn- + cleanup-timeout' value is low for your use-case. + Default 1 seconds --enable-proxy-protocol Default: False. If used, will enable proxy protocol. Only version 1 is currently supported. diff --git a/proxy/core/work/threadless.py b/proxy/core/work/threadless.py index e8f7339d..7caadbb7 100644 --- a/proxy/core/work/threadless.py +++ b/proxy/core/work/threadless.py @@ -20,6 +20,7 @@ from typing import ( cast, ) +from ...common.flag import flags as proxy_flags from ...common.types import Readables, Writables, SelectableEvents from ...common.logger import Logger from ...common.constants import ( @@ -37,6 +38,20 @@ T = TypeVar('T') logger = logging.getLogger(__name__) +proxy_flags.add_argument( + '--inactive-conn-cleanup-timeout', + default=DEFAULT_INACTIVE_CONN_CLEANUP_TIMEOUT, + help='Time after which inactive works must be cleaned up. ' + + 'Increase this value if your backend services are slow to response ' + + 'or when proxy.py is handling a high volume. When running proxy.py on Google Cloud (GCP) ' + + "you may see 'backend_connection_closed_before_data_sent_to_client', with curl clients " + + "you may see 'Empty reply from server' error when '--inactive-conn-cleanup-timeout' " + + 'value is low for your use-case. Default {0} seconds'.format( + DEFAULT_INACTIVE_CONN_CLEANUP_TIMEOUT, + ), +) + + class Threadless(ABC, Generic[T]): """Work executor base class. @@ -87,7 +102,7 @@ class Threadless(ABC, Generic[T]): SelectableEvents, ] = {} self.wait_timeout: float = DEFAULT_WAIT_FOR_TASKS_TIMEOUT - self.cleanup_inactive_timeout: float = DEFAULT_INACTIVE_CONN_CLEANUP_TIMEOUT + self.cleanup_inactive_timeout: float = self.flags.inactive_conn_cleanup_timeout self._total: int = 0 # When put at the top, causes circular import error # since integrated ssh tunnel was introduced.