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

Temporary memory leak in FutureImpl.executors #8640

Merged
merged 5 commits into from
Nov 8, 2023

Conversation

jglick
Copy link
Member

@jglick jglick commented Oct 25, 2023

Alarmed by this thread I tried to see if I could reproduce a memory leak from running K8s builds with WebSocket. I could not reproduce any major leak, but did find some minor issues.

Testing done

Without patch, the test fails with this reference chain:

private static jenkins.model.Jenkins jenkins.model.Jenkins.theInstance->
hudson.model.Hudson@39f8cf44-queue->
hudson.model.Queue@d78af81-leftItems->
com.google.common.cache.LocalCache$LocalManualCache@7a55a792-localCache->
com.google.common.cache.LocalCache@4816e261-segments->
[Lcom.google.common.cache.LocalCache$Segment;@de1aeaf-[1]->
com.google.common.cache.LocalCache$Segment@619f68f4-table->
java.util.concurrent.atomic.AtomicReferenceArray@5d30ba49-array->
[Ljava.lang.Object;@251e4e2e-[2]->
com.google.common.cache.LocalCache$StrongWriteEntry@e03c78d-valueReference->
com.google.common.cache.LocalCache$StrongValueReference@586c2859-referent->
hudson.model.Queue$LeftItem@6425b839-future->
hudson.model.queue.FutureImpl@7665f1fd-executors->
java.util.HashSet@76f2bac1-map->
java.util.HashMap@1ebad322-table->
[Ljava.util.HashMap$Node;@49eb0aac-[2]->
java.util.HashMap$Node@5f7e9273-key->
hudson.model.Executor@94d52cf-owner->
hudson.slaves.SlaveComputer@65397da8

LeftItems are kept around for 5m.

Proposed changelog entries

  • Some agent-related objects could be kept in memory after being disconnected and removed from the computer list.

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

Maintainer checklist

test/pom.xml Outdated Show resolved Hide resolved
j.buildAndAssertSuccess(p);
Computer computer = agent.toComputer();
WeakReference<Computer> computerRef = new WeakReference<>(computer);
WeakReference<Channel> channelRef = new WeakReference<>((Channel) computer.getChannel());
Copy link
Member Author

Choose a reason for hiding this comment

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

Just in case there was some problem with the Channel separately from the Computer. I could not reproduce any in this test, other than jenkinsci/remoting#694 which was reproduced interactively.

@jglick jglick marked this pull request as ready for review October 25, 2023 11:23
@NotMyFault NotMyFault added the bug For changelog: Minor bug. Will be listed after features label Oct 26, 2023
@NotMyFault NotMyFault requested a review from a team October 26, 2023 20:43
@@ -95,4 +95,8 @@ public synchronized void setAsCancelled() {
synchronized void addExecutor(@NonNull Executor executor) {
this.executors.add(executor);
}

synchronized void finished() {
executors.clear();
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes jenkinsci/jenkins-test-harness#672 is still on my list of things to look at, but I believe it is only tangentially related to this PR in that they both happen to involve code run from WorkUnitContext.synchronizeEnd; this PR is about the executors list, which is used only if Future.cancel is called, and does not interact directly with the Future done condition.

@NotMyFault NotMyFault requested a review from timja November 4, 2023 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 Nov 4, 2023
@MarkEWaite MarkEWaite merged commit e4fe504 into jenkinsci:master Nov 8, 2023
17 checks passed
@jglick jglick deleted the computersCollected branch November 13, 2023 19:03
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.

5 participants