[JENKINS-71970] Memory leak involving BufferedBuildListener
#311
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
JENKINS-71970, amending #309.
Reproduced by running
mvn hpi:run
withplus updating
workflow-support
from UC and installingmock-slave
, creating a mock slave, and runningthen
watch 'jmap -histo:live …
or
watch 'jmap -histo:live … | fgrep BufferedBuildListener'
There were multiple issues. First of all, removing the listener on
Channel.onClosed
is not enough (and may in fact be useless) when there are lots of different listeners being created while the channel is open. The listener needed to be associated with the stream (BufferedBuildListener
), not itsReplacement
which is intended to be transient. Closing the stream (if that ever happens) should also remove the listener. And collecting the stream (which happens routinely) should remove the listener.With the fix, I was able to run thousands of
sh
steps in a row on the same open agent channel, and memory did not increase significantly (in particular thebyte[]
usage would go up to ~10Mb but then drop again), nor did any classes from this package stay in the top screenful.