timja / jenkins-gh-issues-poc-06-18

0 stars 0 forks source link

[JENKINS-8992] Jenkins chooses reserved port for communication with agent #6388

Open timja opened 13 years ago

timja commented 13 years ago

I use Jenkins 1.397.
When I start jobs on slaves (jnlp-slaves and windows-service-slaves) sometimes I get following error, so that I have to restart the build multiple times until the exception does not appear.

[ak4.main.branch-4.3-M1-BSF] $ java -Xmx1024M -Dfile.encoding=Cp850 -cp C:\Jenkins\maven-agent.jar;C:\Jenkins\classworlds.jar hudson.maven.agent.Main "C:\Program Files (x86)\Entwicklung\apache-maven-2.1.0" C:\Users\mkr.ARCHIKART\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\20\22feb5d4-6a7aca32 C:\Jenkins\maven-interceptor.jar 80 C:\Jenkins\maven2.1-interceptor.jar
Exception in thread "main" java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.(Unknown Source)
at java.net.Socket.(Unknown Source)
at hudson.maven.agent.Main.main(Main.java:124)
at hudson.maven.agent.Main.main(Main.java:62)

When it succeeds there messages like:

[ak4.main.branch-4.3-M1-BSF] $ java -Xmx1024M -Dfile.encoding=Cp850 -cp C:\Jenkins\maven-agent.jar;C:\Jenkins\classworlds.jar hudson.maven.agent.Main "C:\Program Files (x86)\Entwicklung\apache-maven-2.1.0" C:\Users\mkr.ARCHIKART\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\20\22feb5d4-6a7aca32 C:\Jenkins\maven-interceptor.jar 55046 C:\Jenkins\maven2.1-interceptor.jar

As I understand the logs, the Jenkins slave is instructed to communicate with Jenkins server on Port 80. But on port 80 there is another application running on the maschine, that contains Jenkins server.
So possible solutions would be to retry with another port, configure a list of ports to be avoided or configure a range of ports to be used.


Originally reported by namue, imported from: Jenkins chooses reserved port for communication with agent
  • status: Open
  • priority: Major
  • resolution: Unresolved
  • imported: 2022/01/10
timja commented 13 years ago

kohsuke:

The way it works is that Jenkins asks the OS to bind a server socket to any available port, then it finds out the port that's given to it. I'm surprised that Windows chose to allocate privileged port like 80, but because of the order of events, this cannot be the cause of the connection failure problem — if the port 80 was already occupied, Jenkins wouldn't have gotten that port number in the first place.

(And besides, in your line of reasoning, the connection would succeed, if a process already binds to that port, right?)

timja commented 13 years ago

namue:

The server containing Jenkins is an Ubuntu. On this server there is also an apache on port 80.
The client containing the Jenkins-Slave is an WINXP. On this client there shouldn't be other port in use.

Where is this port 80, that is in the java-command? I thought this is the port on the server. So this could an error ob ubuntu.

What I noticed is, that the frequency of exception of this kind depends on the slave. I have one slave that nearly every time has this exception and another one that most times runs without exception.

Any ideas what could be checked?

timja commented 13 years ago

kohsuke:

This port is opened on the slave where the build is run, which is Windows in this case.

timja commented 13 years ago

namue:

I checked the ports, that were opened. When the exception appeared the slave tried to connect to localhost:80.
So I tried to prevent jenkins from choosing port 80 by setting up a tomcat running on the slave on port 80, so that jenkins should use this port.
But when I ran the build I got following exception:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at hudson.maven.agent.Main.main(Main.java:127)
at hudson.maven.agent.Main.main(Main.java:62)
Caused by: java.io.EOFException: unexpected stream termination
at hudson.remoting.Channel.(Channel.java:375)
at hudson.remoting.Channel.(Channel.java:338)
at hudson.remoting.Channel.(Channel.java:305)
at hudson.remoting.Channel.(Channel.java:297)
at hudson.remoting.Launcher.main(Launcher.java:403)
at hudson.remoting.Launcher.main(Launcher.java:398)
at hudson.remoting.Launcher.main(Launcher.java:394)
... 6 more