[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.
This commit is contained in:
Shi Su 2021-01-19 00:23:36 -08:00 committed by GitHub
parent 52afc801b4
commit afee1a851c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -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

33
dockers/docker-fpm-frr/bgpd.sh Executable file
View File

@ -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 </dev/tcp/${addr}/${port}; do sleep 0.1;done"
if [ "$?" != "0" ]; then
logger -p error "Error: zebra is not ready to accept connections"
fi
exec /usr/lib/frr/bgpd "$@"

View File

@ -51,7 +51,7 @@ dependent_startup=true
dependent_startup_wait_for=zebra:running
[program:bgpd]
command=/usr/lib/frr/bgpd -A 127.0.0.1 -M snmp
command=/usr/bin/bgpd.sh -A 127.0.0.1 -M snmp
priority=5
stopsignal=KILL
autostart=false