I have a Jenkins server that keeps running out of memory and cannot create native threads. I’ve upped the memory and installed the Monitoring plugin.
There are about 150 projects on the server, and I’ve been watching the thread count creep up all day. It is now around 990. I expect when it hits 1024, which is the user limit for threads, Jenkins will run out of memory again.
[edit]: I have hit 1016 threads and am now getting the out of memory error
Is this an appropriate number of threads for Jenkins to be running? How can I tell Jenkins to destroy threads when it is finished with them?
tl;dr:
There was a post-build action running a bash script that didn’t return anything via stderr or stdout to Jenkins. Therefore, every time the build ran, threads would be created and get stuck
waiting. I resolved this issue by having the bash script return anexitstatus.long answer
I am running Jenkins on CentOS and have installed in via the RPM. In terms of modifying the Winstone servlet container, you can change that in Jenkin’s init script in
/etc/sysctrl/jenkins. However the options above only control the number of HTTP threads that are created, not the number of threads overall.That would be a solution if my threads were hanging on accessing an HTTP API of Jenkins as part of a post-commit action. However, using the ever-handy Monitoring plugin mentioned in my question, I inspected the stuck threads.
The threads were stuck on something in the
com.trilead.ssh2.channelpackage. ThegetChannelDatamethod has awhile(true)loop that looks for output on thestderrorstdoutof an ssh stream. The thread was getting suck in that loop because nothing was coming through. I learned this on GrepCode.This was because the post-build action was to execute a command via SSH onto a server and execute a bash script that would inspect a git repo. However, the git repo was misconfigured and the git command would error, but the
exit 1status did not bubble up through the bash script (partially due to a misformed if-elif-else statement).The script completed and the build was considered a success, but somehow the thread handling the SSH connection from Jenkins was left hanging due to this git error.
But thank you for your help on this question!