Skip to content

Commit

Permalink
[JENKINS-41730] - Add option to ignore the X-Jenkins-Agent-Protocols
Browse files Browse the repository at this point in the history
…header (#146)

* [JENKINS-41730] - Add option to ignore the X-Jenkins-Agent-Protocols header + improve diagnostics

- [x] Add the `org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver.ignoreJenkinsAgentProtocolsHeader` property, which disables the cache
- [x] Print warning in the case if the list of supported protocols is empty
- [x] Add documentation

* [JENKINS-41730] - Switch to org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver.protocolNamesToTry according to the feedback from @stephenc

* [JENKINS-41730] - Pront the list of supported protocols iff it is not empty

* [JENKINS-41730] - Get rid of unnecessary line breaks
  • Loading branch information
oleg-nenashev committed Feb 13, 2017
1 parent f61c460 commit 612cc27
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
12 changes: 10 additions & 2 deletions docs/configuration.md
Expand Up @@ -99,10 +99,18 @@ These properties require independent configuration on both sides of the channel.
<td>org.jenkinsci.remoting.nio.NioChannelHub.disabled</td>
<td>false</td>
<td>2.62.3</td>
<td>?</td>
<td>TODO</td>
<td><a href="https://issues.jenkins-ci.org/browse/JENKINS-39290">JENKINS-39290</a></td>
<td>Boolean flag to disable NIO-based socket connection handling, and switch back to classic IO. Used to isolate the problem.</td>
</tr>-
</tr>
<tr>
<td>org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver.protocolNamesToTry</td>
<td>false</td>
<td>TODO</td>
<td>TODO</td>
<td><a href="https://issues.jenkins-ci.org/browse/JENKINS-41730">JENKINS-41730</a></td>
<td>If specified, only the protocols from the list will be tried during the connection. The option provides protocol names, but the order of the check is defined internally and cannot be changed.</td>
</tr>
<!--Template
<tr>
<td></td>
Expand Down
Expand Up @@ -76,6 +76,16 @@ public class JnlpAgentEndpointResolver {

private String tunnel;

/**
* If specified, only the protocols from the list will be tried during the connection.
* The option provides protocol names, but the order of the check is defined internally and cannot be changed.
* This option can be also used in order to workaround issues when the headers cannot be delivered
* from the server due to whatever reason (e.g. JENKINS-41730).
* @since TODO
*/
private static String PROTOCOL_NAMES_TO_TRY =
System.getProperty(JnlpAgentEndpointResolver.class.getName() + ".protocolNamesToTry");

public JnlpAgentEndpointResolver(String... jenkinsUrls) {
this.jenkinsUrls = new ArrayList<String>(Arrays.asList(jenkinsUrls));
}
Expand Down Expand Up @@ -164,6 +174,7 @@ public JnlpAgentEndpoint resolve() throws IOException {
host = defaultString(first(header(con, "X-Jenkins-JNLP-Host")), salURL.getHost());
List<String> protocols = header(con, "X-Jenkins-Agent-Protocols");
if (protocols != null) {
// Take the list of protocols to try from the headers
agentProtocolNames = new HashSet<String>();
for (String names : protocols) {
for (String name : names.split(",")) {
Expand All @@ -173,7 +184,31 @@ public JnlpAgentEndpoint resolve() throws IOException {
}
}
}

if (agentProtocolNames.isEmpty()) {
LOGGER.log(Level.WARNING, "Received the empty list of supported protocols from the server. " +
"All protocols are disabled on the master side OR the 'X-Jenkins-Agent-Protocols' header is corrupted (JENKINS-41730). " +
"In the case of the header corruption as a workaround you can use the " +
"'org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver.protocolNamesToTry' system property " +
"to define the supported protocols.");
} else {
LOGGER.log(Level.INFO, "Remoting server accepts the following protocols: {0}", agentProtocolNames);
}
}

if (PROTOCOL_NAMES_TO_TRY != null) {
// Take a list of protocols to try from the system property
agentProtocolNames = new HashSet<String>();
LOGGER.log(Level.INFO, "Ignoring the list of supported remoting protocols provided by the server, because the " +
"'org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver.protocolNamesToTry' property is defined. Will try {0}", PROTOCOL_NAMES_TO_TRY);
for (String name : PROTOCOL_NAMES_TO_TRY.split(",")) {
name = name.trim();
if (!name.isEmpty()) {
agentProtocolNames.add(name);
}
}
}

String idHeader = first(header(con, "X-Instance-Identity"));
RSAPublicKey identity = null;
if (idHeader != null) {
Expand Down

0 comments on commit 612cc27

Please sign in to comment.