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

Failed to listen to incoming slave connection after fixing port through init.groovy.d

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reopened (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Component/s: core
    • Labels:
      None
    • Similar Issues:

      Description

      When using a init.groovy.d script to set the slave agent port to a fixed value (like the official docker image for Jenkins does), Jenkins shows an error message that seem to tell us that it failed to listen to the agent port.

      java.net.BindException: Failed to listen on port 10000 because it's already in use.
      at hudson.TcpSlaveAgentListener.<init>(TcpSlaveAgentListener.java:74)
      at jenkins.model.Jenkins.<init>(Jenkins.java:825)
      at hudson.model.Hudson.<init>(Hudson.java:83)
      at hudson.model.Hudson.<init>(Hudson.java:79)
      at hudson.WebAppMain$3.run(WebAppMain.java:225)
      Caused by: java.net.BindException: Address already in use
      at sun.nio.ch.Net.bind0(Native Method)
      at sun.nio.ch.Net.bind(Net.java:436)
      at sun.nio.ch.Net.bind(Net.java:428)
      at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
      at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
      at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:67)
      at hudson.TcpSlaveAgentListener.<init>(TcpSlaveAgentListener.java:72)
      ... 4 more

      As a workaround, people have been adding delays, but really the issue is that we have the following sequence of events occurring :

      • Jenkins init
      • init.groovy.d
        • calls Jenkins.getInstance(). setSlaveAgentPort(xxx)
          • behind the scenes, this call starts the TcpSlaveAgentListener
      • initializes TcpSlaveAgentListener, but doesn't suppose that it may have been started before => the port is already taken, hence the error message above.

        Attachments

          Activity

          Hide
          dogfood dogfood added a comment -

          Integrated in jenkins_main_trunk #4257
          [FIXED JENKINS-29798] Failed to listen to incoming slave connection (Revision 7dfa765d8b7562ea25b8eab6c26d8c7a5ca6ef1b)
          JENKINS-29798 Add a lock to serialize updates of tcpSlaveAgentListener (Revision 03bba487296dd7d0f44a0c235724c3b7fb41cd69)

          Result = UNSTABLE
          vincent latombe : 7dfa765d8b7562ea25b8eab6c26d8c7a5ca6ef1b
          Files :

          • changelog.html
          • core/src/main/java/jenkins/model/Jenkins.java

          vincent latombe : 03bba487296dd7d0f44a0c235724c3b7fb41cd69
          Files :

          • core/src/main/java/jenkins/model/Jenkins.java
          Show
          dogfood dogfood added a comment - Integrated in jenkins_main_trunk #4257 [FIXED JENKINS-29798] Failed to listen to incoming slave connection (Revision 7dfa765d8b7562ea25b8eab6c26d8c7a5ca6ef1b) JENKINS-29798 Add a lock to serialize updates of tcpSlaveAgentListener (Revision 03bba487296dd7d0f44a0c235724c3b7fb41cd69) Result = UNSTABLE vincent latombe : 7dfa765d8b7562ea25b8eab6c26d8c7a5ca6ef1b Files : changelog.html core/src/main/java/jenkins/model/Jenkins.java vincent latombe : 03bba487296dd7d0f44a0c235724c3b7fb41cd69 Files : core/src/main/java/jenkins/model/Jenkins.java
          Hide
          iamveritas ovi craciun added a comment - - edited

          I can still see this happening
          Jenkins ver. 2.190.3, windows OS

          Failed to listen to incoming agent connections
          java.net.BindException: Address already in use: bind
          at sun.nio.ch.Net.bind0(Native Method)
          at sun.nio.ch.Net.bind(Unknown Source)
          at sun.nio.ch.Net.bind(Unknown Source)
          at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
          at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
          at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
          at hudson.TcpSlaveAgentListener.<init>(TcpSlaveAgentListener.java:103)
          Caused: java.net.BindException: Failed to listen on port 49994 because it's already in use.
          at hudson.TcpSlaveAgentListener.<init>(TcpSlaveAgentListener.java:105)
          at jenkins.model.Jenkins.launchTcpSlaveAgentListener(Jenkins.java:1287)
          at jenkins.model.Jenkins.<init>(Jenkins.java:983)
          at hudson.model.Hudson.<init>(Hudson.java:85)
          at hudson.model.Hudson.<init>(Hudson.java:81)
          at hudson.WebAppMain$3.run(WebAppMain.java:233)

          the netstat reveals the port is occupied by a process id which points to services.exe
          I did not installed any new app on this server, it is just another aws instance spawned. It used to work just fine before.
          I have serious reasons to believe this is a problem with how the port is binded first and then maybe the code flow is losing it and tries to bind again without releases the initial connection?...

          Show
          iamveritas ovi craciun added a comment - - edited I can still see this happening Jenkins ver. 2.190.3, windows OS Failed to listen to incoming agent connections java.net.BindException: Address already in use: bind at sun.nio.ch.Net.bind0(Native Method) at sun.nio.ch.Net.bind(Unknown Source) at sun.nio.ch.Net.bind(Unknown Source) at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source) at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source) at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source) at hudson.TcpSlaveAgentListener.<init>(TcpSlaveAgentListener.java:103) Caused: java.net.BindException: Failed to listen on port 49994 because it's already in use. at hudson.TcpSlaveAgentListener.<init>(TcpSlaveAgentListener.java:105) at jenkins.model.Jenkins.launchTcpSlaveAgentListener(Jenkins.java:1287) at jenkins.model.Jenkins.<init>(Jenkins.java:983) at hudson.model.Hudson.<init>(Hudson.java:85) at hudson.model.Hudson.<init>(Hudson.java:81) at hudson.WebAppMain$3.run(WebAppMain.java:233) the netstat reveals the port is occupied by a process id which points to services.exe I did not installed any new app on this server, it is just another aws instance spawned. It used to work just fine before. I have serious reasons to believe this is a problem with how the port is binded first and then maybe the code flow is losing it and tries to bind again without releases the initial connection?...
          Hide
          brendanh Brendan Holmes added a comment - - edited

          Did you find a solution ovi craciun? We're experiencing this port 50000 conflict too running in docker. I expect it's a race condition. Our test jenkins with the same configuration, but fewer jobs & no persistent storage doesn't experience it.

          Show
          brendanh Brendan Holmes added a comment - - edited Did you find a solution ovi craciun ? We're experiencing this port 50000 conflict too running in docker. I expect it's a race condition. Our test jenkins with the same configuration, but fewer jobs & no persistent storage doesn't experience it.
          Hide
          iamveritas ovi craciun added a comment -

          Brendan Holmes It's been several months and I really do not remember exactly how I got around this/fixed this. I think I just changed the port to the next one and it stopped having this problem.
          We encountered numerous problems with jenkins, to my unpleasant surprise. I am still astounded at how many problems one can encounter with jenkins vs its reputation in the wild.

          Show
          iamveritas ovi craciun added a comment - Brendan Holmes It's been several months and I really do not remember exactly how I got around this/fixed this. I think I just changed the port to the next one and it stopped having this problem. We encountered numerous problems with jenkins, to my unpleasant surprise. I am still astounded at how many problems one can encounter with jenkins vs its reputation in the wild.
          Hide
          brendanh Brendan Holmes added a comment -

          Yes changing the port to something other than 50000 seems to have fixed for us too. Thanks

          Show
          brendanh Brendan Holmes added a comment - Yes changing the port to something other than 50000 seems to have fixed for us too. Thanks

            People

            Assignee:
            vlatombe Vincent Latombe
            Reporter:
            vlatombe Vincent Latombe
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated: