From afee1a851c5e96c54bfb933bd82fe369df932a88 Mon Sep 17 00:00:00 2001 From: Shi Su <67605788+shi-su@users.noreply.github.com> Date: Tue, 19 Jan 2021 00:23:36 -0800 Subject: [PATCH] [bgpd]: Check zebra is ready to connect when starting bgpd (#6478) Fix #5026 There is a race condition between zebra server accepts connections and bgpd tries to connect. Bgpd has a chance to try to connect before zebra is ready. In this scenario, bgpd will try again after 10 seconds and operate as normal within these 10 seconds. As a consequence, whatever bgpd tries to sent to zebra will be missing in the 10 seconds. To avoid such a scenario, bgpd should start after zebra is ready to accept connections. --- dockers/docker-fpm-frr/Dockerfile.j2 | 1 + dockers/docker-fpm-frr/bgpd.sh | 33 +++++++++++++++++++ .../frr/supervisord/supervisord.conf.j2 | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100755 dockers/docker-fpm-frr/bgpd.sh diff --git a/dockers/docker-fpm-frr/Dockerfile.j2 b/dockers/docker-fpm-frr/Dockerfile.j2 index ab8b585899..69e3655d0c 100644 --- a/dockers/docker-fpm-frr/Dockerfile.j2 +++ b/dockers/docker-fpm-frr/Dockerfile.j2 @@ -55,6 +55,7 @@ COPY ["TSB", "/usr/bin/TSB"] COPY ["TSC", "/usr/bin/TSC"] COPY ["files/supervisor-proc-exit-listener", "/usr/bin"] COPY ["critical_processes", "/etc/supervisor"] +COPY ["bgpd.sh", "/usr/bin/"] RUN chmod a+x /usr/bin/TSA && \ chmod a+x /usr/bin/TSB && \ chmod a+x /usr/bin/TSC diff --git a/dockers/docker-fpm-frr/bgpd.sh b/dockers/docker-fpm-frr/bgpd.sh new file mode 100755 index 0000000000..c61a594a1e --- /dev/null +++ b/dockers/docker-fpm-frr/bgpd.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +addr="127.0.0.1" +port=2601 + +function help() +{ + echo "This script aims to ensure zebra is ready to accept connections before starting bgpd" + echo "Usage: $0 [options] [bgpd options]" + echo "Options:" + echo " -a Zebra address" + echo " -o Zebra port" + exit 1 +} + +while getopts ":a:o:h" opt; do + case "${opt}" in + h) help + ;; + a) addr=${OPTARG} + ;; + o) port=${OPTARG} + ;; + esac +done +shift $((OPTIND-1)) + +timeout 5s bash -c -- "until