From 3a4a388d6ee99149e8f2dd6b4f6c3ca185db0857 Mon Sep 17 00:00:00 2001 From: Damian Shaw <111310636+notatallshaw-work@users.noreply.github.com> Date: Wed, 7 Sep 2022 17:43:31 -0400 Subject: [PATCH 1/3] Only server to IPV6 when dual stack is confirmed --- airflow/utils/serve_logs.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/airflow/utils/serve_logs.py b/airflow/utils/serve_logs.py index 447cff6d900ba..4a02056da9de1 100644 --- a/airflow/utils/serve_logs.py +++ b/airflow/utils/serve_logs.py @@ -19,6 +19,7 @@ import collections import logging import os +import socket import gunicorn.app.base from flask import Flask, abort, request, send_from_directory @@ -143,13 +144,14 @@ def serve_logs(): worker_log_server_port = conf.getint('logging', 'WORKER_LOG_SERVER_PORT') - # Make sure to have both an IPv4 and an IPv6 interface. - # Gunicorn can bind multiple addresses, see https://docs.gunicorn.org/en/stable/settings.html#bind. - options = [ - GunicornOption("bind", f"0.0.0.0:{worker_log_server_port}"), - GunicornOption("bind", f"[::]:{worker_log_server_port}"), - GunicornOption("workers", 2), - ] + # If dual stack is available and IPV6_V6ONLY is not enabled on the socket + # then when IPV6 is bound to it will also bind to IPV4 automatically + if getattr(socket, "has_dualstack_ipv6", bool)(): + bind_option = GunicornOption("bind", f"[::]:{worker_log_server_port}") + else: + bind_option = GunicornOption("bind", f"0.0.0.0:{worker_log_server_port}") + + options = [bind_option, GunicornOption("workers", 2)] StandaloneGunicornApplication(wsgi_app, options).run() From 8bde54e6229e0243a24dd3ef00b261ba6bfaed00 Mon Sep 17 00:00:00 2001 From: Ash Berlin-Taylor Date: Thu, 8 Sep 2022 09:25:16 +0100 Subject: [PATCH 2/3] Update airflow/utils/serve_logs.py --- airflow/utils/serve_logs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airflow/utils/serve_logs.py b/airflow/utils/serve_logs.py index 4a02056da9de1..bb98358c976f1 100644 --- a/airflow/utils/serve_logs.py +++ b/airflow/utils/serve_logs.py @@ -146,7 +146,7 @@ def serve_logs(): # If dual stack is available and IPV6_V6ONLY is not enabled on the socket # then when IPV6 is bound to it will also bind to IPV4 automatically - if getattr(socket, "has_dualstack_ipv6", bool)(): + if getattr(socket, "has_dualstack_ipv6", False)(): bind_option = GunicornOption("bind", f"[::]:{worker_log_server_port}") else: bind_option = GunicornOption("bind", f"0.0.0.0:{worker_log_server_port}") From 5e5cb8de9fabbde708beec7c670a7eb8c49487f4 Mon Sep 17 00:00:00 2001 From: Ash Berlin-Taylor Date: Thu, 8 Sep 2022 09:26:42 +0100 Subject: [PATCH 3/3] Update airflow/utils/serve_logs.py --- airflow/utils/serve_logs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airflow/utils/serve_logs.py b/airflow/utils/serve_logs.py index bb98358c976f1..fb600a0b465a2 100644 --- a/airflow/utils/serve_logs.py +++ b/airflow/utils/serve_logs.py @@ -146,7 +146,7 @@ def serve_logs(): # If dual stack is available and IPV6_V6ONLY is not enabled on the socket # then when IPV6 is bound to it will also bind to IPV4 automatically - if getattr(socket, "has_dualstack_ipv6", False)(): + if getattr(socket, "has_dualstack_ipv6", lambda: False)(): bind_option = GunicornOption("bind", f"[::]:{worker_log_server_port}") else: bind_option = GunicornOption("bind", f"0.0.0.0:{worker_log_server_port}")