Enable socket keepalives

Connections from airflow-worker can be long-lived (e.g. when applying
large Armada manifests), and are prone to disconnection due to network
inactivity.

This change enables socket keepalives in the default HTTP connection
socket options for urllib3. Modules that use urllib3 (e.g. requests)
will be affected by this change.

Change-Id: I067a5edbbdff06f45394e772ebb16d5012987b6c
This commit is contained in:
Phil Sphicas 2022-03-13 22:19:52 -07:00
parent 034b906dd6
commit 5217c645d2
1 changed files with 9 additions and 0 deletions

View File

@ -0,0 +1,9 @@
import socket
import urllib3
if (socket.SOL_SOCKET, socket.SO_KEEPALIVE,
1) not in urllib3.connection.HTTPConnection.default_socket_options:
urllib3.connection.HTTPConnection.default_socket_options += [
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
]