Skip to content

Commit

Permalink
[Related to JENKINS-34121] Allow disabling the protocols individually (
Browse files Browse the repository at this point in the history
…#83)

- Also ensure that a fatal unexpected error in one protocol does not prevent a fall-back
  • Loading branch information
stephenc authored and oleg-nenashev committed May 12, 2016
1 parent 6d9c03c commit 43793e5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/main/java/hudson/remoting/Engine.java
Expand Up @@ -302,12 +302,24 @@ public void run() {
Channel channel = null;

// Try available protocols.
boolean triedAtLeastOneProtocol = false;
for (JnlpProtocol protocol : protocols) {
if (!protocol.isEnabled()) {
events.status("Protocol " + protocol.getName() + " is not enabled, skipping");
continue;
}
triedAtLeastOneProtocol = true;
events.status("Trying protocol: " + protocol.getName());
try {
channel = protocol.establishChannel(jnlpSocket, channelBuilder);
} catch (IOException ioe) {
events.status("Protocol failed to establish channel", ioe);
events.status("Protocol " + protocol.getName() + " failed to establish channel", ioe);
} catch (RuntimeException e) {
events.status("Protocol " + protocol.getName() + " encountered a runtime error", e);
} catch (Error e) {
events.status("Protocol " + protocol.getName() + " could not be completed due to an error", e);
} catch (Throwable e) {
events.status("Protocol " + protocol.getName() + " encountered an unexpected exception", e);
}

// On success do not try other protocols.
Expand All @@ -322,7 +334,12 @@ public void run() {

// If no protocol worked.
if (channel == null) {
onConnectionRejected("None of the protocols were accepted");
if (triedAtLeastOneProtocol) {
onConnectionRejected("None of the protocols were accepted");
} else {
onConnectionRejected("None of the protocols are enabled");
return; // exit
}
continue;
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/jenkinsci/remoting/engine/JnlpProtocol.java
Expand Up @@ -57,6 +57,14 @@ public abstract class JnlpProtocol {
this.events = events;
}

/**
* Whether this protocol is enabled for connecting.
* @return {@code true} if this protocol is enabled.
*/
public boolean isEnabled() {
return !Boolean.getBoolean(getClass().getName()+".disabled");
}

/**
* Get the name of the protocol.
*/
Expand Down

1 comment on commit 43793e5

@oleg-nenashev
Copy link
Member

Choose a reason for hiding this comment

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

Please sign in to comment.