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

[JENKINS-70206] Lazy initialization of JnlpSlaveAgentProtocol4 #7514

Merged

Conversation

jglick
Copy link
Member

@jglick jglick commented Dec 12, 2022

See JENKINS-70206. Supersedes #7512.

Currently just unconditionally returning a value from getName, and letting handle throw up any problems. We could try to disable the protocol (return null from getName) in case of problems, such as a missing instance-identity plugin (#6585), but that would be a bit more complicated, possibly cause extra work during startup even when this protocol is actually unused, and it is not clear to me that this would actually improve behavior for the user anyway.

Testing done

Just relying on automated tests here. Not sure if we can tell whether the otherwise flaky test is more reliable with this patch.

Proposed changelog entries

  • Delaying initialization of cryptography needed for TCP inbound agents unless and until such an agent is connected.

Maintainer checklist

Before the changes are marked as ready-for-merge:

  • There are at least two (2) approvals for the pull request and no outstanding requests for change.
  • Conversations in the pull request are over, or it is explicit that a reviewer is not blocking the change.
  • Changelog entries in the pull request title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood.
  • Proper changelog labels are set so that the changelog can be generated automatically.
  • If the change needs additional upgrade steps from users, the upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the pull request title (see example).
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

@jglick jglick requested a review from basil December 12, 2022 13:04
@jglick jglick requested a review from a team December 12, 2022 13:08
* @throws IOException if things go wrong.
*/
public JnlpSlaveAgentProtocol4() throws KeyStoreException, KeyManagementException, IOException {
private synchronized void init() throws Exception {
Copy link
Member Author

Choose a reason for hiding this comment

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

Arguably more legible just below handle but this keeps the diff smaller.

init();
} catch (IOException x) {
throw x;
} catch (Exception x) {
Copy link
Member Author

Choose a reason for hiding this comment

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

KeyStoreException, KeyManagementException but also IllegalStateException…just seemed simpler to catch anything.

@@ -175,11 +149,18 @@ public String getDisplayName() {

@Override
public String getName() {
return handler.getName();
return "JNLP4-connect"; // matches JnlpProtocol4Handler.getName
Copy link
Member

Choose a reason for hiding this comment

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

Extract to constant?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could, though this would require a new remoting release.

Copy link
Member

Choose a reason for hiding this comment

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

Ah right, missed the fact it was somewhere else.

Comment on lines +157 to +163
try {
init();
} catch (IOException x) {
throw x;
} catch (Exception x) {
throw new IOException(x);
}
Copy link
Member

@Vlatombe Vlatombe Dec 12, 2022

Choose a reason for hiding this comment

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

Suggested change
try {
init();
} catch (IOException x) {
throw x;
} catch (Exception x) {
throw new IOException(x);
}
if (handler == null) {
try {
init();
} catch (IOException x) {
throw x;
} catch (Exception x) {
throw new IOException(x);
}
}

to avoid taking the object monitor in the general case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Would have to think about whether that requires making handler be volatile. Does not seem necessary since handle should be called once per actual agent connection, which is many orders of magnitude more expensive than acquiring an uncontended monitor.

Copy link
Member

Choose a reason for hiding this comment

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

FTR this pattern would work, but as that page itself mentions, "in modern JVMs with efficient uncontended synchronization the performance difference is often negligible". The performance of the current version is certainly fine as described in the previous comment.

Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

This PR is now ready for merge. We will merge it after approximately 24 hours if there is no negative feedback. Please see the merge process documentation for more information about the merge process. Thanks!

@basil basil added ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback bug For changelog: Minor bug. Will be listed after features labels Dec 12, 2022
@basil basil merged commit f5e90fe into jenkinsci:master Dec 13, 2022
@jglick jglick deleted the JnlpSlaveAgentProtocol4-JENKINS-70206 branch December 13, 2022 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For changelog: Minor bug. Will be listed after features ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants