Description of problem: While trying to register one of our machines on the RedHat network, I ran rhn_register and it would hang with an error message saying it could not connect to the host (Connection Timed Out, 110). After investigation, I found that it was hanging at the function findHostByRoute trying to connect to serverURL directly (not using the specified proxy). I believe the function is made to return the hostname, according to the DNS by using the IP address bound to the interface used for the connect(), and it should only be used in a worst case scenario (hostname is not set, etc.) It should only do this if the hostname has not been found/well detected, however it seems like it does it all the time because the machine's detected hostname is overriden at some point (which is what I believe is the bug). This is the actual part of the script where it does not seem to work properly. ----- netdict['hostname'] = socket.gethostname() try: netdict['ipaddr'] = socket.gethostbyname(socket.gethostname()) except: netdict['ipaddr'] = "127.0.0.1" # THIS PART WILL, I BELIEVE, ALWAYS OVERRIDE # THEREFORE ALWAYS RUN findHostByRoute() netdict['hostname'] = 'localhost.localdomain' netdict['ipaddr'] = "127.0.0.1" if netdict['hostname'] == 'localhost.localdomain' or \ netdict['ipaddr'] == "127.0.0.1": hostname, ipaddr = findHostByRoute() netdict['hostname'] = hostname netdict['ipaddr'] = ipaddr return netdict ----- This is what I believe it should be: ----- netdict['hostname'] = socket.gethostname() try: netdict['ipaddr'] = socket.gethostbyname(socket.gethostname()) except: netdict['ipaddr'] = "127.0.0.1" netdict['hostname'] = 'localhost.localdomain' if netdict['hostname'] == 'localhost.localdomain' or \ netdict['ipaddr'] == "127.0.0.1": hostname, ipaddr = findHostByRoute() netdict['hostname'] = hostname netdict['ipaddr'] = ipaddr return netdict ----- That way, it will only override the hostname and ip address detected if socket.gethostbyname(socket.gethostname()) was not succesful instead of doing it ALL THE TIME. Version-Release number of selected component (if applicable): rhn_register-2.9.2-1.2.1AS How reproducible: Try to register to the network behind a firewall that does not allow direct connections to port 80, going through a proxy (squid in this case, but irrelevant). Steps to Reproduce: 1. try to register through a proxy while behind a firewall that does not allow connecting to port 80 directly 2. 3. Actual results: rhn_register fails without proceeding to the registration, saying "Error 110 Connection Timed Out" while trying to connect to serverUrl port 80. Expected results: Succesful registration Additional info:
I also experienced this bug while trying to run rhn_register behind a firewall. I tried Phillipe's proposed fix, and it does solve the problem, but not in all cases. It occurs to me that the statements in the findHostByRoute() function in hardware.py will still cause a fatal error behind a firewall/web proxy because they are not wrapped in a try block. I think that the findHostByRoute() function either needs to be re-written to handle proxies, or at the very least, made to properly handle exceptions that might occur (such as the timeout that will occur when the connection cannot be made through the proxy). Best regards, Jason Burks
*** This bug has been marked as a duplicate of 112276 ***
It definitely needs to be rewritten or patched... I'd like to include some details: If /etc/hosts is not setup correctly (ie. you just installed and used DHCP) it will contain: 127.0.0.1 yourhostname.yourdomainname, etc... So the function will run socket.gethostbyname(socket.gethostname()) and will get 127.0.0.1 for return, and therefore fail. Philippe April
Changed to 'CLOSED' state since 'RESOLVED' has been deprecated.