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-74975] Fix Semaphore over-allocation of permits / limit all CleanupTasks #495

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Dohbedoh
Copy link

@Dohbedoh Dohbedoh commented Dec 10, 2024

(amends #237)

The CleanupTask of the built-in node were scheduled instantly without acquiring permit from the Semaphore but they were releasing permits, hence creating additional permits over time. Reducing the effectiveness of the limit overtime.

Add the Jenkins built-in node to list of nodes to be limited.

NOTES: I guess another solution is to continue not limit the number of CleanupTask executed for the built-in node but that looks rather confusing in the first place to have a CLEANUP_THREAD_LIMIT that only partially limit the Cleanup tasks..

Testing done

  • Create a Jenkins instance with -Djenkins.branch.WorkspaceLocatorImpl\$Deleter.CLEANUP_THREAD_LIMIT=1
  • In Manage Jenkins > Script Console, execute jenkins.branch.WorkspaceLocatorImpl.Deleter.cleanupPool.availablePermits() and validate that it shows 1
  • Create a Multibranch pipeline with at least one branch
  • Add a filter to have all branches discarded and removed by the orphaned item strategy and save
  • In Manage Jenkins > Script Console, execute jenkins.branch.WorkspaceLocatorImpl.Deleter.cleanupPool.availablePermits() and validate that it still shows 1

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@Dohbedoh Dohbedoh requested a review from a team as a code owner December 10, 2024 07:33
@@ -382,22 +389,27 @@ public static class Deleter extends ItemListener {

private static /* almost final */ int CLEANUP_THREAD_LIMIT = SystemProperties.getInteger(Deleter.class.getName() + ".CLEANUP_THREAD_LIMIT", Integer.valueOf(0)).intValue();

private final transient ExecutorService executorService = Executors.newSingleThreadExecutor(threadFactory());
Copy link
Member

Choose a reason for hiding this comment

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

I'm unsure; Will this survive a reload configuration from disk?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this class is saved to disk at all; it's just an extension. If you restart Jenkins while a lot of deletion tasks are waiting to run, I do think they will all be lost if that's what you mean, but it looks like that was the case before this PR too.

@@ -382,22 +389,27 @@ public static class Deleter extends ItemListener {

private static /* almost final */ int CLEANUP_THREAD_LIMIT = SystemProperties.getInteger(Deleter.class.getName() + ".CLEANUP_THREAD_LIMIT", Integer.valueOf(0)).intValue();

private final transient ExecutorService executorService = Executors.newSingleThreadExecutor(threadFactory());
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this class is saved to disk at all; it's just an extension. If you restart Jenkins while a lot of deletion tasks are waiting to run, I do think they will all be lost if that's what you mean, but it looks like that was the case before this PR too.

src/main/java/jenkins/branch/WorkspaceLocatorImpl.java Outdated Show resolved Hide resolved
@dwnusbaum dwnusbaum requested review from rsandell and a team December 17, 2024 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants