We run Zookeeper in a container environment where DNS is not stable. As recommended by the documentation, we set electionPortBindRetry to 0 (keeps retrying forever).
On some instances, we get the following exception in an infinite loop, even though the address already became resolve-able:
Zookeeper does not actually retry the DNS resolution, it just keeps using the old failed result.
This happens because the InetSocketAddress is created once and the DNS lookup happens when it is created.
This issue has come up previously in https://issues.apache.org/jira/browse/ZOOKEEPER-1506 but it appears to still happen here.
I have attached a repro.tar.gz to help reproduce this issue. Steps:
- Untar repro.tar.gz
- docker-compose up
- See the exception keeps happening for zk-2, not for the others
- Open db.test and uncomment the zk-2 line, increment the serial and save
- Wait a few seconds for the DNS to refresh
- Verify that you can resolve zk-2.test now (dig @172.16.60.2 zk-2.test) but the error keeps appearing
I have also attached a patch that resolves this. The patch will retry DNS resolution if the address is still unresolved every time it tries to create the server socket.