NetDB unable to resolve DNS when application was launched without network
Original Reporter info from Mantis: Shebuka
-
Reporter name: Anton S.
Original Reporter info from Mantis: Shebuka
- Reporter name: Anton S.
Description:
If network is down when the application is launched then ResolveName and/or ResolveHostByName fails (one returns a negative value and other returns False), and even after the network is went online every subsequent call to ResolveName and/or ResolveHostByName will still fail.
I have a clue that this happens because when you start the app and there is no network connection /etc/resolv.conf file is pointing to no file (because /etc/resolv.conf is a link and /var/run/resolv.conf in not present) and because inside netdb's InitResolver, CheckResolveFileAge is set to False the file with resolve dns server is never reread (never updated by CheckResolveFile) on subsequent calls, so even if network goes up ResolveHostByName always return False leaving 0.0.0.0 as ip...
But even if you set CheckResolveFileAge to True then it still fails because ResolveFileAge will contain the FileAge of the link /etc/resolv.conf and not the FileAge of new/updated /var/run/resolv.conf, so ResolveFileAge&LtPos;FileAge(ResolveFileName) will be always False and GetDnsServers never called again.
Steps to reproduce:
Shutdown your network
Launch attached test application and click on Button
Restore your network and wait until it acquire IP and DNS addresses
Click again on Button
Additional information:
The discussion related to how i'v found this bug:
http://www.lazarus.freepascal.org/index.php/topic,14857.msg79133.html#msg79133
And as i can see from related bug it also happens on Debian.
Can this be short term solution?
{$ifdef darwin}
SResolveFile = '/var/run/resolv.conf';
{$else}
SResolveFile = '/etc/resolv.conf';
{$endif}
Mantis conversion info:
- Mantis ID: 20484
- OS: OS X
- OS Build: 10.6.8
- Platform: Mac
- Version: 2.4.4
- Fixed in version: 2.6.4
- Fixed in revision: 23891 (#b8a571fb)
- Monitored by: » Shebuka (Anton S.)
- Target version: 2.7.1