baidu / braft

An industrial-grade C++ implementation of RAFT consensus algorithm based on brpc, widely used inside Baidu to build highly-available distributed systems.
Apache License 2.0
3.95k stars 881 forks source link

example/counter中脚本语句在特定情况下会导致IP绑定错误从而造成样例运行失败 #287

Open Super-long opened 3 years ago

Super-long commented 3 years ago

example/counter/run_xxx.shexample/block/run_xxx.sh中IP变量的获取是执行如下语句hostname -i | awk '{print $NF}'

容器的网络模式默认是bridge,在这种模式下容器启动后会通过DHCP获取一个地址,这就导致hostname -i会生成两项,导致在宿主机中使用了容器生成的虚拟网卡,从而导致执行样例失败:

20210512194450552 20210512194225309

现在的问题是如何优雅的解决这个问题,如果IP的获取不通过shell,而使用C++,这种问题很好解决,我们只需要跑自连接,成功当前环境就是宿主机,否则就是容器环境。但是是否有方法在不改变现有获取配置的方法的情况下解决这个问题。