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-72796] stable context classloader for Computer.threadPoolForRemoting #9012

Merged
merged 2 commits into from
Mar 6, 2024

Conversation

jtnord
Copy link
Member

@jtnord jtnord commented Mar 4, 2024

Whilst the threadpool used reset the context classloader at the end of any task, it did not ensure that the initial classloader used was anything sepcific, rather it would use whatever the calling threads contextClassLoader was.

This is now fixed as we use the Jenkins WebApp classloader (same as the Timer) which is used by (A)PeriodicTasks.

Whilst we should really not have a context classloader (aka null) and this should be set where needed by code, almost everywhere in Jenkins the context classloader is already the webapp classloader, and so setting this to be different depending on how things where called would seemingly be a little scary. Arguably this and other context classloaders should be all set to null and any code that wants different should be changed, but this is a larger piece of work that would have potential impact on an unknown number of plugins in the ecosystem, so this fix uses what was set > 90% of the time.

See JENKINS-72796.

Testing done

Proposed changelog entries

  • Ensure threads in the Computer.threadPoolForRemotingexecutor service always have the Jenkins webapp ClassLoader set as the context ClassLoader to prevent random class loading issues when code is running in this ExecutorService.

Proposed upgrade guidelines

N/A

Submitter checklist

Edit tasklist title
Beta Give feedback Tasklist Submitter checklist, more options

Delete tasklist

Delete tasklist block?
Are you sure? All relationships in this tasklist will be removed.
  1. The Jira issue, if it exists, is well-described.
    Options
  2. The changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developers, depending on the change) and are in the imperative mood (see examples). Fill in the Proposed upgrade guidelines section only if there are breaking changes or changes that may require extra steps from users during upgrade.
    Options
  3. There is automated testing or an explanation as to why this change has no tests.
    Options
  4. New public classes, fields, and methods are annotated with @Restricted or have @since TODO Javadocs, as appropriate.
    Options
  5. New deprecations are annotated with @Deprecated(since = "TODO") or @Deprecated(forRemoval = true, since = "TODO"), if applicable.
    Options
  6. New or substantially changed JavaScript is not defined inline and does not call eval to ease future introduction of Content Security Policy (CSP) directives (see documentation).
    Options
  7. For dependency updates, there are links to external changelogs and, if possible, full differentials.
    Options
  8. For new APIs and extension points, there is a link to at least one consumer.
    Options

Desired reviewers

@mention

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

Maintainer checklist

Edit tasklist title
Beta Give feedback Tasklist Maintainer checklist, more options

Delete tasklist

Delete tasklist block?
Are you sure? All relationships in this tasklist will be removed.
  1. There are at least two (2) approvals for the pull request and no outstanding requests for change.
    Options
  2. Conversations in the pull request are over, or it is explicit that a reviewer is not blocking the change.
    Options
  3. Changelog entries in the pull request title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood.
    Options
  4. Proper changelog labels are set so that the changelog can be generated automatically.
    Options
  5. 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).
    Options
  6. 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).
    Options

…Remoting

Whilst the threadpool used reset the context classloader at the end of
any task, it did not ensure that the initial c;lassloader used was
anything sepcific, rather it would use whatever the calling threads
contextClassLoader was.

This is now fixed as we use the Jenkins WebApp classloader (same as
the Timer) which is used by (A)PeriodicTasks.

Whilst we should really not have a context classloader (aka null) and
this should be set where needed by code, almost everywhere in Jenkins
the context classloader is already the webapp classloader, and so
setting this to be different depending on how things where called would
seemingly be a little scary.  Arguably this and other context
classloaders should be all set to null and any code that wants different
should be changed, but this is a larger piece of work that would have
potential impact on an unknown number of plugins in the ecosystem, so
this fix uses what was set > 90% of the time.
@jtnord jtnord requested review from jglick and a team March 4, 2024 15:48
Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

/label ready-for-merge


This PR is now ready for merge, after ~24 hours, we will merge it if there's no negative feedback.

Thanks!

@comment-ops-bot comment-ops-bot bot added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Mar 4, 2024
@jtnord jtnord added the bug For changelog: Minor bug. Will be listed after features label Mar 5, 2024
@NotMyFault NotMyFault merged commit 89195cc into jenkinsci:master Mar 6, 2024
17 checks passed
@kmartens27
Copy link

Hi @jtnord, would there be a better version of the changelog entry for this PR? If there should not be a changelog entry, we can definitely adjust, but if there should be something included, would you be able to clarify a bit what that would be?

@jtnord
Copy link
Member Author

jtnord commented Mar 8, 2024

Hi @jtnord, would there be a better version of the changelog entry for this PR? If there should not be a changelog entry, we can definitely adjust, but if there should be something included, would you be able to clarify a bit what that would be?

Hi @kmartens27 thanks for the reminder - I have updated the suggested changelog entry.

  • JENKINS-72796, Ensure threads in the Computer.threadPoolForRemoting executor service always have the Jenkins webapp ClassLoader set as the context ClassLoader to prevent random class loading issues when code is running in this ExecutorService.

@jtnord jtnord deleted the JENKINS-72796 branch March 8, 2024 14:17
@kmartens27
Copy link

Thank you so much!

krisstern pushed a commit to krisstern/jenkins that referenced this pull request Apr 2, 2024
…Remoting (jenkinsci#9012)

* [JENKINS-72796] stable context classloader for Computer.threadPoolForRemoting

Whilst the threadpool used reset the context classloader at the end of
any task, it did not ensure that the initial c;lassloader used was
anything sepcific, rather it would use whatever the calling threads
contextClassLoader was.

This is now fixed as we use the Jenkins WebApp classloader (same as
the Timer) which is used by (A)PeriodicTasks.

Whilst we should really not have a context classloader (aka null) and
this should be set where needed by code, almost everywhere in Jenkins
the context classloader is already the webapp classloader, and so
setting this to be different depending on how things where called would
seemingly be a little scary.  Arguably this and other context
classloaders should be all set to null and any code that wants different
should be changed, but this is a larger piece of work that would have
potential impact on an unknown number of plugins in the ecosystem, so
this fix uses what was set > 90% of the time.

* Update core/src/test/java/hudson/model/ComputerTest.java

---------

Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
(cherry picked from commit 89195cc)
krisstern pushed a commit to krisstern/jenkins that referenced this pull request Apr 4, 2024
…Remoting (jenkinsci#9012)

* [JENKINS-72796] stable context classloader for Computer.threadPoolForRemoting

Whilst the threadpool used reset the context classloader at the end of
any task, it did not ensure that the initial c;lassloader used was
anything sepcific, rather it would use whatever the calling threads
contextClassLoader was.

This is now fixed as we use the Jenkins WebApp classloader (same as
the Timer) which is used by (A)PeriodicTasks.

Whilst we should really not have a context classloader (aka null) and
this should be set where needed by code, almost everywhere in Jenkins
the context classloader is already the webapp classloader, and so
setting this to be different depending on how things where called would
seemingly be a little scary.  Arguably this and other context
classloaders should be all set to null and any code that wants different
should be changed, but this is a larger piece of work that would have
potential impact on an unknown number of plugins in the ecosystem, so
this fix uses what was set > 90% of the time.

* Update core/src/test/java/hudson/model/ComputerTest.java

---------

Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
(cherry picked from commit 89195cc)
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
6 participants