Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED JENKINS-38539] Turn on SO_KEEPALIVE and provide CLI option to turn it off again #110

Merged
merged 2 commits into from
Sep 28, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/main/java/hudson/remoting/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ public void run() {

private boolean noReconnect;

/**
* Determines whether the socket will have {@link Socket#setKeepAlive(boolean)} set or not.
*
* @since TODO
*/
private boolean keepAlive = true;

private JarCache jarCache = new FileSystemJarCache(new File(System.getProperty("user.home"),".jenkins/cache/jars"),true);

public Engine(EngineListener listener, List<URL> hudsonUrls, String secretKey, String slaveName) {
Expand Down Expand Up @@ -178,6 +185,24 @@ public void setNoReconnect(boolean noReconnect) {
this.noReconnect = noReconnect;
}

/**
* Returns {@code true} if and only if the socket to the master will have {@link Socket#setKeepAlive(boolean)} set.
*
* @return {@code true} if and only if the socket to the master will have {@link Socket#setKeepAlive(boolean)} set.
*/
public boolean isKeepAlive() {
return keepAlive;
}

/**
* Sets the {@link Socket#setKeepAlive(boolean)} to use for the connection to the master.
*
* @param keepAlive the {@link Socket#setKeepAlive(boolean)} to use for the connection to the master.
*/
public void setKeepAlive(boolean keepAlive) {
this.keepAlive = keepAlive;
}

public void setCandidateCertificates(List<X509Certificate> candidateCertificates) {
this.candidateCertificates = candidateCertificates == null
? null
Expand Down Expand Up @@ -409,6 +434,7 @@ private Socket connect(@CheckForNull String host, @CheckForNull String port) thr
s.connect(targetAddress);

s.setTcpNoDelay(true); // we'll do buffering by ourselves
s.setKeepAlive(keepAlive);

// set read time out to avoid infinite hang. the time out should be long enough so as not
// to interfere with normal operation. the main purpose of this is that when the other peer dies
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/hudson/remoting/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ public boolean verify(String s, SSLSession sslSession) {
@Option(name="-noReconnect",usage="Doesn't try to reconnect when a communication fail, and exit instead")
public boolean noReconnect = false;

@Option(name = "-noKeepAlive",
usage = "Do not open the socket to the master with SO_KEEPALIVE enabled")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not tell me much as a user. Why would I want that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue that you do not want this unless you know why you do not want it... I could make it a system property rather than a CLI option... should only be required if we have a fundamental misunderstanding of how sockets work...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also rephrase it a bit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olivergondza My plan is to create a documentation page, which will clarify options and their potential impact. By now I think the current summary string is acceptable. Do you agree?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

public boolean noKeepAlive = false;

public static void main(String... args) throws Exception {
Launcher launcher = new Launcher();
CmdLineParser parser = new CmdLineParser(launcher);
Expand Down Expand Up @@ -229,6 +233,9 @@ public void run() throws Exception {
if (this.noReconnect) {
jnlpArgs.add("-noreconnect");
}
if (this.noKeepAlive) {
jnlpArgs.add("-noKeepAlive");
}
try {
hudson.remoting.jnlp.Main._main(jnlpArgs.toArray(new String[jnlpArgs.size()]));
} catch (CmdLineException e) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/hudson/remoting/jnlp/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public class Main {
usage="If the connection ends, don't retry and just exit.")
public boolean noReconnect = false;

@Option(name="-noKeepAlive",
usage="Do not open the socket to the master with SO_KEEPALIVE enabled")
public boolean noKeepAlive = false;

@Option(name = "-cert",
usage = "Specify additional X.509 encoded PEM certificates to trust when connecting to Jenkins " +
"root URLs. If starting with @ then the remainder is assumed to be the name of the " +
Expand Down Expand Up @@ -173,6 +177,7 @@ public Engine createEngine() {
if(jarCache!=null)
engine.setJarCache(new FileSystemJarCache(jarCache,true));
engine.setNoReconnect(noReconnect);
engine.setKeepAlive(!noKeepAlive);
if (candidateCertificates != null && !candidateCertificates.isEmpty()) {
CertificateFactory factory;
try {
Expand Down