Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-15698

Perforce can't get hostname for slaves

    Details

    • Similar Issues:

      Description

      I have lots of Perforce warnings in log.
      Perforce settings are atteched.

      WARNING: Could not get hostname for slave rusbuilder-ims
      Nov 2, 2012 10:12:26 AM hudson.plugins.perforce.PerforceSCM getEffectiveClientName
      WARNING: Could not get hostname for slave rusbuilder-ims
      Nov 2, 2012 10:12:26 AM hudson.plugins.perforce.PerforceSCM getEffectiveClientName
      WARNING: Could not get hostname for slave rusbuilder-ims
      Nov 2, 2012 10:12:26 AM hudson.plugins.perforce.PerforceSCM getEffectiveClientName
      WARNING: Could not get hostname for slave rusbuilder-ims
      Nov 2, 2012 10:12:26 AM hudson.plugins.perforce.PerforceSCM getEffectiveClientName
      WARNING: Could not get hostname for slave rusbuilder-ims

        Attachments

          Issue Links

            Activity

            alexey_larsky Alexey Larsky created issue -
            Hide
            alexey_larsky Alexey Larsky added a comment -
            Show
            alexey_larsky Alexey Larsky added a comment - The same issue was closed https://issues.jenkins-ci.org/browse/JENKINS-6257
            Hide
            rpetti Rob Petti added a comment -

            This is a problem with core, unfortunately. Getting the hostname of a machine using java is actually quite difficult, so it doesn't work 100% of the time. Check that the hostname is resolvable in DNS, and that the slave isn't running more than one networking interface. Apart from that, there's really nothing else that can be done.

            Show
            rpetti Rob Petti added a comment - This is a problem with core, unfortunately. Getting the hostname of a machine using java is actually quite difficult, so it doesn't work 100% of the time. Check that the hostname is resolvable in DNS, and that the slave isn't running more than one networking interface. Apart from that, there's really nothing else that can be done.
            Hide
            alexey_larsky Alexey Larsky added a comment - - edited

            Hostname is resolvable, network interface is only one. I also added to etc\hosts self address.
            Warning still present.

            PS. OS Windows 7 Pro x64 SP1 on master and slave.

            Show
            alexey_larsky Alexey Larsky added a comment - - edited Hostname is resolvable, network interface is only one. I also added to etc\hosts self address. Warning still present. PS. OS Windows 7 Pro x64 SP1 on master and slave.
            alexey_larsky Alexey Larsky made changes -
            Field Original Value New Value
            Link This issue depends on JENKINS-6257 [ JENKINS-6257 ]
            Hide
            jameshowe James Howe added a comment -

            What version of java is on the slave?

            Show
            jameshowe James Howe added a comment - What version of java is on the slave?
            Hide
            alexey_larsky Alexey Larsky added a comment -

            jre-6u45-windows-i586

            Show
            alexey_larsky Alexey Larsky added a comment - jre-6u45-windows-i586
            Hide
            jameshowe James Howe added a comment -

            Try updating to Java 7. I find only my Java 6 slaves have this issue.

            Show
            jameshowe James Howe added a comment - Try updating to Java 7. I find only my Java 6 slaves have this issue.
            Hide
            alexey_larsky Alexey Larsky added a comment -

            After updating Java to jre-7u60-windows-x64.exe on master and slave the issue still present.
            Strange what it happens only with one of 5 slaves.

            Jun 26, 2014 3:54:15 PM WARNING hudson.plugins.perforce.PerforceSCM getEffectiveClientName
            Could not get hostname for slave builder-slave-1

            Show
            alexey_larsky Alexey Larsky added a comment - After updating Java to jre-7u60-windows-x64.exe on master and slave the issue still present. Strange what it happens only with one of 5 slaves. Jun 26, 2014 3:54:15 PM WARNING hudson.plugins.perforce.PerforceSCM getEffectiveClientName Could not get hostname for slave builder-slave-1
            Hide
            rodrigozrusso Rodrigo Russo added a comment -

            I have the same problem.
            I noticed that Perforce Plugin is using gethostname() from Computer class that is from Jenkins Core code as Rob said.
            Then, I got the method getHostName() from perforce plugin and execute it on script console in Jenkins Master.
            I also got the code snippet from Computer class (jenkins/core/src/main/java/hudson/model/Computer.java) that get the hostname using InetAddress class
            and execute it on script console in the Slave that have this problem.

            Code snippet executed in Master:

            String getHostName(Node node) {
            String host = null;
            try {
            Computer c = node.toComputer();
            if (c != null)

            { host = c.getHostName(); }

            } catch (Exception ex)

            { // fallback to finally }

            finally {
            if (host == null)

            { println "Could not get hostname for slave " << node.getDisplayName(); host = "UNKNOWNHOST"; }

            }
            if (host.contains("."))

            { host = String.valueOf(host.subSequence(0, host.indexOf('.'))); }

            return host;
            }

            Jenkins h = Jenkins.getInstance();
            for (Node n : h.getNodes())

            { println "Slave: " << n.name; println "Hostname: " << getHostName( n); println "--------------------------------" }

            Result

            Slave: Linux_Slave_1
            Hostname: server01
            --------------------------------
            Slave: Windows_Slave_1
            Could not get hostname for slave Windows_Slave_1
            Hostname: UNKNOWNHOST

            Code snippet executed in Slave that the hostname is unknow (http://jenkins.xpto.net/computer/Windows_Slave_1/script):

            import java.net.InetAddress;

            println "Get hostname by dns"
            InetAddress ia = InetAddress.getByName("server02.xpto.net");
            println ia.getCanonicalHostName();
            println "----------------------------------"
            println "Get hostname by name"
            ia = InetAddress.getByName("server02");
            println ia.getCanonicalHostName();
            println "----------------------------------"
            println "Get hostname by ip"
            ia = InetAddress.getByName("10.0.0.2");
            println ia.getCanonicalHostName();

            Result

            Get hostname by dns
            server02.xpto.net
            ----------------------------------
            Get hostname by name
            server02.xpto.net
            ----------------------------------
            Get hostname by ip
            server02.xpto.net

            So, for my surprise in the slave it can resolve the hostname.

            The firewall in this windows machine is disabled.

            Do you thing that it could be because of the network interface ?
            Do you thing that this menssage "WARNING: Could not get hostname for slave ..." is a warning log?
            What do you think if we change the log level to FINE, due to it spam the jenkins log and don't bring any relevant information ?

            Show
            rodrigozrusso Rodrigo Russo added a comment - I have the same problem. I noticed that Perforce Plugin is using gethostname() from Computer class that is from Jenkins Core code as Rob said. Then, I got the method getHostName() from perforce plugin and execute it on script console in Jenkins Master. I also got the code snippet from Computer class (jenkins/core/src/main/java/hudson/model/Computer.java) that get the hostname using InetAddress class and execute it on script console in the Slave that have this problem. Code snippet executed in Master: String getHostName(Node node) { String host = null; try { Computer c = node.toComputer(); if (c != null) { host = c.getHostName(); } } catch (Exception ex) { // fallback to finally } finally { if (host == null) { println "Could not get hostname for slave " << node.getDisplayName(); host = "UNKNOWNHOST"; } } if (host.contains(".")) { host = String.valueOf(host.subSequence(0, host.indexOf('.'))); } return host; } Jenkins h = Jenkins.getInstance(); for (Node n : h.getNodes()) { println "Slave: " << n.name; println "Hostname: " << getHostName( n); println "--------------------------------" } Result Slave: Linux_Slave_1 Hostname: server01 -------------------------------- Slave: Windows_Slave_1 Could not get hostname for slave Windows_Slave_1 Hostname: UNKNOWNHOST Code snippet executed in Slave that the hostname is unknow ( http://jenkins.xpto.net/computer/Windows_Slave_1/script): import java.net.InetAddress; println "Get hostname by dns" InetAddress ia = InetAddress.getByName("server02.xpto.net"); println ia.getCanonicalHostName(); println "----------------------------------" println "Get hostname by name" ia = InetAddress.getByName("server02"); println ia.getCanonicalHostName(); println "----------------------------------" println "Get hostname by ip" ia = InetAddress.getByName("10.0.0.2"); println ia.getCanonicalHostName(); Result Get hostname by dns server02.xpto.net ---------------------------------- Get hostname by name server02.xpto.net ---------------------------------- Get hostname by ip server02.xpto.net So, for my surprise in the slave it can resolve the hostname. The firewall in this windows machine is disabled. Do you thing that it could be because of the network interface ? Do you thing that this menssage "WARNING: Could not get hostname for slave ..." is a warning log? What do you think if we change the log level to FINE, due to it spam the jenkins log and don't bring any relevant information ?
            Hide
            oleg_nenashev Oleg Nenashev added a comment -

            According to Javadoc, hostname is null if...
            > ... if the host name cannot be computed (for example because this computer is offline, because the slave is behind the firewall, etc.)

            The hostname is being calculated using java.net.InetAddress::getCanonicalHostName(), so the real result depends on the implementation in JVM. I see a glitch in Perforce Plugin code, which may cause an NPE. However, it should not cause the described behavior.

            Currently, the most of plugin EnvVar substitutions will fail if they really need ${hostname}.
            I would vote for merging https://github.com/jenkinsci/perforce-plugin/pull/66

            Show
            oleg_nenashev Oleg Nenashev added a comment - According to Javadoc, hostname is null if... > ... if the host name cannot be computed (for example because this computer is offline, because the slave is behind the firewall, etc.) The hostname is being calculated using java.net.InetAddress::getCanonicalHostName(), so the real result depends on the implementation in JVM. I see a glitch in Perforce Plugin code, which may cause an NPE. However, it should not cause the described behavior. Currently, the most of plugin EnvVar substitutions will fail if they really need ${hostname}. I would vote for merging https://github.com/jenkinsci/perforce-plugin/pull/66
            alskor Alex Java made changes -
            Link This issue is related to JENKINS-29734 [ JENKINS-29734 ]
            Hide
            alskor Alex Java added a comment -

            IMHO reducing log prints for unresolvable hostnames is hardly a solution if Perforce Plugin fails to checkout code to a new workspace when hostname cannot be resolved...
            I submitted a proposal to use IP addresses: JENKINS-29734

            Show
            alskor Alex Java added a comment - IMHO reducing log prints for unresolvable hostnames is hardly a solution if Perforce Plugin fails to checkout code to a new workspace when hostname cannot be resolved... I submitted a proposal to use IP addresses: JENKINS-29734
            Hide
            jameshowe James Howe added a comment -

            Alexey, it doesn't fail to checkout. Everything else is fine.

            Show
            jameshowe James Howe added a comment - Alexey, it doesn't fail to checkout. Everything else is fine.
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 146457 ] JNJira + In-Review [ 176624 ]
            ircbot Jenkins IRC Bot made changes -
            Component/s p4-plugin [ 19224 ]
            Component/s perforce-plugin [ 15506 ]

              People

              • Assignee:
                Unassigned
                Reporter:
                alexey_larsky Alexey Larsky
              • Votes:
                3 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                • Created:
                  Updated: