Skip to content

Commit

Permalink
Temporary memory leak in FutureImpl.executors (#8640)
Browse files Browse the repository at this point in the history
* Temporary memory leak in `FutureImpl.executors`

* jenkinsci/jenkins-test-harness#669 released

* Skip new test on Windows #8640 (comment)
  • Loading branch information
jglick authored Nov 8, 2023
1 parent 942f932 commit e4fe504
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/hudson/model/queue/FutureImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,8 @@ public synchronized void setAsCancelled() {
synchronized void addExecutor(@NonNull Executor executor) {
this.executors.add(executor);
}

synchronized void finished() {
executors.clear();
}
}
1 change: 1 addition & 0 deletions core/src/main/java/hudson/model/queue/WorkUnitContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public void synchronizeEnd(Executor e, Queue.Executable executable, Throwable pr
}
}
}
future.finished();
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions test/src/test/java/hudson/model/ComputerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isA;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
Expand All @@ -39,12 +40,16 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeThat;

import hudson.ExtensionList;
import hudson.Functions;
import hudson.diagnosis.OldDataMonitor;
import hudson.remoting.Channel;
import hudson.slaves.DumbSlave;
import hudson.slaves.OfflineCause;
import java.io.File;
import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import java.util.Map;
Expand All @@ -66,6 +71,7 @@
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient;
import org.jvnet.hudson.test.LoggerRule;
import org.jvnet.hudson.test.MemoryAssert;
import org.jvnet.hudson.test.MockAuthorizationStrategy;
import org.jvnet.hudson.test.MockFolder;
import org.jvnet.hudson.test.SmokeTest;
Expand Down Expand Up @@ -263,4 +269,22 @@ public void testTerminatedNodeAjaxExecutorsDoesNotShowTrace() throws Exception {
j.assertBuildStatus(Result.FAILURE, j.waitForCompletion(b));
}

@Test
public void computersCollected() throws Exception {
assumeThat("Seems to crash the test JVM at least in CI", Functions.isWindows(), is(false));
DumbSlave agent = j.createOnlineSlave();
FreeStyleProject p = j.createFreeStyleProject();
p.setAssignedNode(agent);
j.buildAndAssertSuccess(p);
Computer computer = agent.toComputer();
WeakReference<Computer> computerRef = new WeakReference<>(computer);
WeakReference<Channel> channelRef = new WeakReference<>((Channel) computer.getChannel());
computer.disconnect(null);
computer = null;
j.jenkins.removeNode(agent);
agent = null;
MemoryAssert.assertGC(computerRef, false);
MemoryAssert.assertGC(channelRef, false);
}

}

0 comments on commit e4fe504

Please sign in to comment.