-
Bug
-
Resolution: Fixed
-
Critical
-
Jenkins 2.89.3
ace-editor 1.1
analysis-core 1.93
ansicolor 0.5.2
ant 1.8
antisamy-markup-formatter 1.5
apache-httpcomponents-client-4-api 4.5.3-2.0
artifactory 2.13.1
authentication-tokens 1.3
authorize-project 1.3.0
azure-credentials 1.5.0
bouncycastle-api 2.16.2
branch-api 2.0.18
build-timeout 1.19
build-user-vars-plugin 1.5
checkstyle 3.49
cloudbees-folder 6.2.1
command-launcher 1.2
config-file-provider 2.16.4
copyartifact 1.39
credentials 2.1.16
credentials-binding 1.13
cvs 2.13
dashboard-view 2.9.11
datadog 0.6.2
display-url-api 2.2.0
docker-commons 1.10
docker-workflow 1.14
durable-task 1.17
email-ext 2.61
envinject 2.1.5
envinject-api 1.4
external-monitor-job 1.7
extra-columns 1.18
findbugs 4.71
git 3.6.4
git-client 2.6.0
git-server 1.7
github 1.28.1
github-api 1.90
github-branch-source 2.3.1
gitlab-plugin 1.5.2
gradle 1.28
handlebars 1.1.1
htmlpublisher 1.14
icon-shim 2.0.3
ivy 1.28
jackson2-api 2.8.10.1
jacoco 2.2.1
javadoc 1.4
job-dsl 1.68
jquery 1.12.4-0
jquery-detached 1.2.1
jsch 0.1.54.1
junit 1.23
junit-attachments 1.4.2
ldap 1.18
logstash 1.3.0
mailer 1.20
mapdb-api 1.0.9.0
mask-passwords 2.10.1
matrix-auth 2.2
matrix-project 1.12
maven-plugin 3.0
momentjs 1.1.1
monitoring 1.70.0
notification 1.12
pam-auth 1.3
pipeline-build-step 2.7
pipeline-github-lib 1.0
pipeline-graph-analysis 1.5
pipeline-input-step 2.8
pipeline-milestone-step 1.3.1
pipeline-model-api 1.2.5
pipeline-model-declarative-agent 1.1.1
pipeline-model-definition 1.2.5
pipeline-model-extensions 1.2.5
pipeline-rest-api 2.9
pipeline-stage-step 2.3
pipeline-stage-tags-metadata 1.2.5
pipeline-stage-view 2.9
pipeline-utility-steps 1.5.1
plain-credentials 1.4
progress-bar-column-plugin 1.0
rebuild 1.27
resource-disposer 0.8
scm-api 2.2.6
script-security 1.40
slack 2.3
sonar 2.6.1
ssh-credentials 1.13
ssh-slaves 1.25
structs 1.14
subversion 2.10.2
swarm 3.10
test-results-analyzer 0.3.4
text-finder 1.10
throttle-concurrents 2.0.1
timestamper 1.8.9
token-macro 2.3
windows-slaves 1.3.1
workflow-aggregator 2.5
workflow-api 2.25
workflow-basic-steps 2.6
workflow-cps 2.43
workflow-cps-global-lib 2.9
workflow-durable-task-step 2.18
workflow-job 2.17
workflow-multibranch 2.17
workflow-scm-step 2.6
workflow-step-api 2.14
workflow-support 2.17
ws-cleanup 0.34Jenkins 2.89.3 ace-editor 1.1 analysis-core 1.93 ansicolor 0.5.2 ant 1.8 antisamy-markup-formatter 1.5 apache-httpcomponents-client-4-api 4.5.3-2.0 artifactory 2.13.1 authentication-tokens 1.3 authorize-project 1.3.0 azure-credentials 1.5.0 bouncycastle-api 2.16.2 branch-api 2.0.18 build-timeout 1.19 build-user-vars-plugin 1.5 checkstyle 3.49 cloudbees-folder 6.2.1 command-launcher 1.2 config-file-provider 2.16.4 copyartifact 1.39 credentials 2.1.16 credentials-binding 1.13 cvs 2.13 dashboard-view 2.9.11 datadog 0.6.2 display-url-api 2.2.0 docker-commons 1.10 docker-workflow 1.14 durable-task 1.17 email-ext 2.61 envinject 2.1.5 envinject-api 1.4 external-monitor-job 1.7 extra-columns 1.18 findbugs 4.71 git 3.6.4 git-client 2.6.0 git-server 1.7 github 1.28.1 github-api 1.90 github-branch-source 2.3.1 gitlab-plugin 1.5.2 gradle 1.28 handlebars 1.1.1 htmlpublisher 1.14 icon-shim 2.0.3 ivy 1.28 jackson2-api 2.8.10.1 jacoco 2.2.1 javadoc 1.4 job-dsl 1.68 jquery 1.12.4-0 jquery-detached 1.2.1 jsch 0.1.54.1 junit 1.23 junit-attachments 1.4.2 ldap 1.18 logstash 1.3.0 mailer 1.20 mapdb-api 1.0.9.0 mask-passwords 2.10.1 matrix-auth 2.2 matrix-project 1.12 maven-plugin 3.0 momentjs 1.1.1 monitoring 1.70.0 notification 1.12 pam-auth 1.3 pipeline-build-step 2.7 pipeline-github-lib 1.0 pipeline-graph-analysis 1.5 pipeline-input-step 2.8 pipeline-milestone-step 1.3.1 pipeline-model-api 1.2.5 pipeline-model-declarative-agent 1.1.1 pipeline-model-definition 1.2.5 pipeline-model-extensions 1.2.5 pipeline-rest-api 2.9 pipeline-stage-step 2.3 pipeline-stage-tags-metadata 1.2.5 pipeline-stage-view 2.9 pipeline-utility-steps 1.5.1 plain-credentials 1.4 progress-bar-column-plugin 1.0 rebuild 1.27 resource-disposer 0.8 scm-api 2.2.6 script-security 1.40 slack 2.3 sonar 2.6.1 ssh-credentials 1.13 ssh-slaves 1.25 structs 1.14 subversion 2.10.2 swarm 3.10 test-results-analyzer 0.3.4 text-finder 1.10 throttle-concurrents 2.0.1 timestamper 1.8.9 token-macro 2.3 windows-slaves 1.3.1 workflow-aggregator 2.5 workflow-api 2.25 workflow-basic-steps 2.6 workflow-cps 2.43 workflow-cps-global-lib 2.9 workflow-durable-task-step 2.18 workflow-job 2.17 workflow-multibranch 2.17 workflow-scm-step 2.6 workflow-step-api 2.14 workflow-support 2.17 ws-cleanup 0.34
-
-
2.173
tl;dr When the master's connection to an SSH slave times out and a new connection is opened, references to the old Remoting channel still persist in the job and the workspace list. This means that in-use workspaces get handed out to new jobs (because the logic that checks for a workspace being in use doesn't take the reconnect case into account), and then both jobs clobber each other and fail.
I have a Jenkins installation where I am using the SSH slaves plugin to run long-running jobs on two nodes. Every so often, due to networking issues, the nodes lose their connection to the master. When this happens, an I/O error occurs on the Remoting channel, and the following output is printed in the Jenkins console log:
SEVERE: I/O error in channel jenkins-node INFO: Attempting to reconnect jenkins-node [03/16/18 12:50:29] SSH Launch of jenkins-node on jenkins-node.example.com completed in 25,604 ms
As you can see, the node gets disconnected, and then Jenkins reconnects to it. Looking at the logs for the node in the Manage Nodes view, I can see that a brand new SSH connection was opened:
[03/31/18 10:08:57] [SSH] Opening SSH connection to jenkins-node.example.com:22. [03/31/18 10:08:58] [SSH] Authentication successful. [03/31/18 10:08:58] [SSH] The remote user's environment is: [...]
The timestamps reflect the current time, not the time the Jenkins master was originally launched.
So far, so good. Now, bear in mind that I have several long-running jobs using this node, and these jobs keep running after the node disconnects and reconnects. The node never went down, it's just that its network was temporarily unavailable. The jobs keep running on it, and eventually (when the network comes back up) their results make it back to the master under the new Remoting Channel.
At this point, new jobs start (against the newly reconnected node), and here is where the trouble starts. The new jobs get allocated a workspace that is already being used by a currently-running job from before the node disconnect/reconnect. This results in disaster for both jobs, as the new job will do a Git clone and clobber files in the workspace of the already running job. Both jobs will then fail. By the time users notice and contact me, dozens of jobs have failed.
* * *
I started looking into why this happens, and I believe I understand the cause. When Jenkins is allocating workspaces, it starts by calling Computer#getWorkspaeList to get the workspace list for the node in question. This class keeps track of the in-use workspaces in the following map:
private final Map<FilePath,Entry> inUse = new HashMap<FilePath,Entry>();
When a new job runs, a FilePath is constructed for the desired workspace path. The inUse map is then checked to see if that workspace has already been handed out to a running job, which uses FilePath#equals:
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; FilePath that = (FilePath) o; if (channel != null ? !channel.equals(that.channel) : that.channel != null) return false; return remote.equals(that.remote); }
The problem here is that the candidate has the new Remoting channel (because the node disconnected and reconnected), while the entry in inUse has the old channel (because when the job started running, the old channel was still active). As a result, the equality check fails. Jenkins then hands out the workspace to the new job, even as the old job is still using it. Then both jobs clobber each other and fail. I verified that this was happening on my instance by running the following script in the Console Log:
import jenkins.model.Jenkins def computer = null Jenkins.instance.computers.each { if (it.name == 'blackbox-slave2') { computer = it } } println computer.channel computer.workspaceList.inUse.each { key, value -> if (key.channel != computer.channel) { println "'In use' under an old channel (and therefore not really considered in use): " key } } println 'done'
This printed several workspaces that were in the "in use" map under an old channel, and therefore not considered in use anymore from the perspective of a new job.
* * *
As a partial workaround, I can restart the Jenkins instance, which rehydrates the running jobs under the new Remoting channel. This prevents workspaces from being handed out when they are already being used, but it is often too little too late: by the time the problem is noticed, many jobs have already failed.
- duplicates
-
JENKINS-41854 Contextualize a fresh FilePath after an agent reconnection
- Resolved
- links to