Question
How to take a build agent thread dump?
Answer
It is recommended to take an agent thread dump from the Web UI: go to the Agent page, Agent Summary tab, and use the Dump threads on agent action.
If the UI is not accessible, it is possible to take the thread dump manually.
Under Windows
Use the TeamCity-bundled thread dump tool:
<TeamCity agent>\plugins\stacktracesPlugin\bin\x86\JetBrains.TeamCity.Injector.exe <pid_of_java_process>
Note that if the build agent is run as a service, the thread dumping tool must be run from a console with elevated permissions (using Run as Administrator). If the service is run under the System account, the thread dump tool might need to be launched via PsExec.exe -s <path to the tool>\<tool> <options>. When the service is run under a regular user, wrapping the tool invocation in PsExec.exe -u <user> -p <password> <path to the tool>\<tool> <options> might also help.
Under Linux
Run jstack <pid_of_java_process> (using jstack from the same JVM as used by the agent) or kill -3 <pid_of_java_process>. In the latter case, the output will appear in <TeamCity Agent Home>/logs/error.log.
Note that the TeamCity agent consists of two Java processes: the launcher and the agent itself. The agent is triggered by the launcher. Usually, the thread dump from the agent (nested) process is needed.
Capturing thread dumps via the jstack command might require configuring additional agent startup properties to deactivate the DisableAttachMechanism option. This Java option is initially enabled for security reasons to prevent external processes from attaching to a JVM. It is recommended to re-enable it after collecting the required dumps.
Comments
0 comments
Please sign in to leave a comment.