GetHostByName keeps failing

Hi Robert,

I am trying to synchronize BBB clock to NTP time server. The connection to internet is through PPP cellular modem. I can ping any host, such as www.google.com. The c program works some time and fails other time when I run on BBBw, but it works all the time on Debian VirtualBox. When it fails, it fails at gethostbyname () call:

#ifdef GET_HOST_BY_NAME
m_iTries = 0;
server = gethostbyname(host_name);
while ((server == NULL) && m_iTries ++ < 5 ) { //5 seconds
//at_debug(“ERROR no such host=%d,%d\r\n”, NTP_ERR_GET_HOST_BY_NAME, h_errno);
usleep(1000000); //1000 ms
}
if (server == NULL) {
at_debug(“ERROR no such host=%d,%d\r\n”, NTP_ERR_GET_HOST_BY_NAME, h_errno);
return NTP_ERR_GET_HOST_BY_NAME;
}
#endif //GET_HOST_BY_NAME

I added 5 tries as suggested by the following link:

But it still fails, some times.

Any suggestions and hints that may resolve this problem?

Thank You,
David

Hi @dzhou, this sounds like a race between the neworking coming up and ntp starting…

Here is a really really old bug showing a similar situation…

About 4-5 years ago we moved from ntpupdate to systemd-timesyncd to fix a lot of these time issues…

Regards,

Hi Robert,

Thanks for the info.
I think it is related to the NTP server, either the server is too busy, or occasionally, it is rejecting the name resolution. But it is weird that on Debian VirtualBox, it fails on recv() call. On BBBw, if I change ntp server name to “www.google.com”, or others, it never failed once by gethostbyname(). It is a little puzzle to me. Suppose the name resolution is done through the DNS, not the server host itself. I saw a lot of related issues with ntpd. There is no real and reliable solution.

Regards,
David