Skip to content

Commit

Permalink
Change default of [kubernetes] enable_tcp_keepalive to True (apac…
Browse files Browse the repository at this point in the history
…he#15338)

We've seen instances of connection resets happening, particularly in
Azure, that are remedied by enabling tcp_keepalive. Enabling it by
default should be safe and sane regardless of where we are running.

(cherry picked from commit 6e31465)
  • Loading branch information
jedcunningham authored and ashb committed Apr 15, 2021
1 parent 8416679 commit 17fd314
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion airflow/config_templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2065,7 +2065,7 @@
version_added: ~
type: boolean
example: ~
default: "False"
default: "True"
- name: tcp_keep_idle
description: |
When the `enable_tcp_keepalive` option is enabled, TCP probes a connection that has
Expand Down
2 changes: 1 addition & 1 deletion airflow/config_templates/default_airflow.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ delete_option_kwargs =

# Enables TCP keepalive mechanism. This prevents Kubernetes API requests to hang indefinitely
# when idle connection is time-outed on services like cloud load balancers or firewalls.
enable_tcp_keepalive = False
enable_tcp_keepalive = True

# When the `enable_tcp_keepalive` option is enabled, TCP probes a connection that has
# been idle for `tcp_keep_idle` seconds.
Expand Down
8 changes: 4 additions & 4 deletions airflow/kubernetes/kube_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def _enable_tcp_keepalive() -> None:

from urllib3.connection import HTTPConnection, HTTPSConnection

tcp_keep_idle = conf.getint('kubernetes', 'tcp_keep_idle', fallback=120)
tcp_keep_intvl = conf.getint('kubernetes', 'tcp_keep_intvl', fallback=30)
tcp_keep_cnt = conf.getint('kubernetes', 'tcp_keep_cnt', fallback=6)
tcp_keep_idle = conf.getint('kubernetes', 'tcp_keep_idle')
tcp_keep_intvl = conf.getint('kubernetes', 'tcp_keep_intvl')
tcp_keep_cnt = conf.getint('kubernetes', 'tcp_keep_cnt')

socket_options = [
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
Expand Down Expand Up @@ -120,7 +120,7 @@ def get_kube_client(
if config_file is None:
config_file = conf.get('kubernetes', 'config_file', fallback=None)

if conf.getboolean('kubernetes', 'enable_tcp_keepalive', fallback=False):
if conf.getboolean('kubernetes', 'enable_tcp_keepalive'):
_enable_tcp_keepalive()

client_conf = _get_kube_config(in_cluster, cluster_context, config_file)
Expand Down

0 comments on commit 17fd314

Please sign in to comment.