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

Merged
merged 5 commits into from
Feb 11, 2025

Conversation

Dohbedoh
Copy link
Contributor

@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.

@dwnusbaum dwnusbaum requested review from rsandell and a team December 17, 2024 19:42
@Dohbedoh
Copy link
Contributor Author

Dohbedoh commented Jan 24, 2025

@dwnusbaum Can we merge this ?

@dwnusbaum dwnusbaum added the bug label Feb 11, 2025
@dwnusbaum
Copy link
Member

@Dohbedoh sure yes sorry I missed your earlier message

@dwnusbaum dwnusbaum enabled auto-merge February 11, 2025 16:17
@dwnusbaum dwnusbaum merged commit 3f65280 into jenkinsci:master Feb 11, 2025
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants