kubernetes: Error on socket receive: read tcp 127.0.0.1:42499->127.0.0.1:40604: use of closed network connection

What happened:

kubelet logs

Jan 15 07:42:08 node-2 kubelet[1462]: E0115 07:42:08.437831    1462 conn.go:254] Error on socket receive: read tcp 127.0.0.1:42499->127.0.0.1:40584: use of closed network connection
Jan 15 07:42:09 node-2 kubelet[1462]: E0115 07:42:09.268678    1462 conn.go:254] Error on socket receive: read tcp 127.0.0.1:42499->127.0.0.1:40588: use of closed network connection
Jan 15 07:42:09 node-2 kubelet[1462]: E0115 07:42:09.902179    1462 conn.go:254] Error on socket receive: read tcp 127.0.0.1:42499->127.0.0.1:40598: use of closed network connection
Jan 15 07:42:10 node-2 kubelet[1462]: E0115 07:42:10.545228    1462 conn.go:254] Error on socket receive: read tcp 127.0.0.1:42499->127.0.0.1:40604: use of closed network connection
Jan 15 07:42:11 node-2 kubelet[1462]: E0115 07:42:11.147430    1462 conn.go:254] Error on socket receive: read tcp 127.0.0.1:42499->127.0.0.1:40610: use of closed network connection
Jan 15 07:42:11 node-2 kubelet[1462]: E0115 07:42:11.751391    1462 conn.go:254] Error on socket receive: read tcp 127.0.0.1:42499->127.0.0.1:40616: use of closed network connection
Jan 15 07:42:12 node-2 kubelet[1462]: E0115 07:42:12.348913    1462 conn.go:254] Error on socket receive: read tcp 127.0.0.1:42499->127.0.0.1:40622: use of closed network connection
Jan 15 07:42:13 node-2 kubelet[1462]: E0115 07:42:13.185637    1462 conn.go:254] Error on socket receive: read tcp 127.0.0.1:42499->127.0.0.1:40630: use of closed network connection

What you expected to happen:

How to reproduce it (as minimally and precisely as possible):

In my particular case it happens when my jenkins runs jobs. I have jenkins configured with dynamic workers spawned as kubernetes pods (using kubernetes plugin).

I suspect the jenkinsfile node commands are run through kubernetes exec command but not sure I can easily confirm that.

So far (after upgrade from 1.18.x to 1.19.6 which happened this Tuesday, 3 days ago) jenkins was running successfully but one run. That one run crashed with

00:01:34.299  Executing sh script inside container docker of pod jenkins-948444fa-fc18-42a3-a3dc-3cb1bf738475-0t6j8-nh09z
00:01:34.562  Executing command: "docker" "run" "-t" "-d" "-u" "0:0" "-w" <redacted>
00:01:34.562  exit
00:01:34.666  6a0611c6bfe5c6ff2f5dd33c672717492036efbc78efa8f03f9f4ab5cb6309f0
00:01:34.996  time="2021-01-14T23:00:55Z" level=error msg="error waiting for container: context canceled"
00:01:35.033  Executing sh script inside container docker of pod jenkins-948444fa-fc18-42a3-a3dc-3cb1bf738475-0t6j8-nh09z
00:01:35.290  Executing command: "docker" "top" "6a0611c6bfe5c6ff2f5dd33c672717492036efbc78efa8f03f9f4ab5cb6309f0
00:01:35.290  time="2021-01-14T23:00:55Z" level=error msg="error waiting for container: context canceled"" "-eo" "pid,comm" 
00:01:35.290  exit
00:01:35.328  Error response from daemon: page not found
00:01:35.398  [Pipeline] // withDockerContainer
00:01:35.436  [Pipeline] }
00:01:35.525  [Pipeline] // container
00:01:35.573  [Pipeline] }
00:01:35.632  [Pipeline] // stage
00:01:35.691  [Pipeline] }
00:01:35.798  [Pipeline] // node
00:01:35.850  [Pipeline] }
00:01:35.932  [Pipeline] // podTemplate
00:01:35.986  [Pipeline] }
00:01:36.073  [Pipeline] // timeout
00:01:36.164  [Pipeline] End of Pipeline
00:01:36.234  java.io.IOException: Failed to run top '6a0611c6bfe5c6ff2f5dd33c672717492036efbc78efa8f03f9f4ab5cb6309f0
00:01:36.234  time="2021-01-14T23:00:55Z" level=error msg="error waiting for container: context canceled"'. Error: 
00:01:36.234  	at org.jenkinsci.plugins.docker.workflow.client.DockerClient.listProcess(DockerClient.java:152)
00:01:36.234  	at org.jenkinsci.plugins.docker.workflow.WithContainerStep$Execution.start(WithContainerStep.java:199)
00:01:36.234  	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:319)
00:01:36.234  	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:193)
00:01:36.234  	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
00:01:36.234  	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
00:01:36.234  	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
00:01:36.234  	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
00:01:36.234  	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
00:01:36.234  	at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(Docker.groovy:126)
00:01:36.234  	at org.jenkinsci.plugins.docker.workflow.Docker.node(Docker.groovy:66)
00:01:36.234  	at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(Docker.groovy:114)
00:01:36.234  	at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(Docker.groovy)
00:01:36.234  	at WorkflowScript.run(WorkflowScript:51)
00:01:36.234  	at ___cps.transform___(Native Method)
00:01:36.234  	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
00:01:36.234  	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
00:01:36.234  	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
00:01:36.234  	at sun.reflect.GeneratedMethodAccessor206.invoke(Unknown Source)
00:01:36.234  	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
00:01:36.234  	at java.lang.reflect.Method.invoke(Method.java:498)
00:01:36.234  	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
00:01:36.234  	at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46)
00:01:36.234  	at com.cloudbees.groovy.cps.Next.step(Next.java:83)
00:01:36.234  	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
00:01:36.234  	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
00:01:36.234  	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
00:01:36.234  	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
00:01:36.234  	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
00:01:36.234  	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
00:01:36.234  	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
00:01:36.234  	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:185)
00:01:36.234  	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:400)
00:01:36.234  	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96)
00:01:36.234  	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:312)
00:01:36.234  	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:276)
00:01:36.234  	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
00:01:36.234  	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
00:01:36.234  	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:136)
00:01:36.234  	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
00:01:36.234  	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
00:01:36.234  	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
00:01:36.234  	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
00:01:36.234  	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
00:01:36.234  	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
00:01:36.234  	at java.lang.Thread.run(Thread.java:748)
00:01:36.234  Finished: FAILURE

Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version): Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.6", GitCommit:"fbf646b339dc52336b55d8ec85c181981b86331a", GitTreeState:"clean", BuildDate:"2020-12-18T12:01:36Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}
  • Cloud provider or hardware configuration: baremetal
  • OS (e.g: cat /etc/os-release): ubuntu 20.04
  • Kernel (e.g. uname -a): 4.15.0-130-generic #134-Ubuntu SMP Tue Jan 5 20:46:26 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  • Install tools: kubeadm
  • Network plugin and version (if this is a network-related bug):
  • Others:

References:

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

I confirm the problem at the time of version 1.31.4, 1.31.5 in three different environments.

Brief instructions for playback:

  1. Hook into logs of all kube-apiserver instances in ns kube-system.
  2. Execute the following command:
    kubectl -n default exec pod-xxx -- echo "TEST"
    
  3. Is there any reaction in the logs? I have messages of a similar nature:
    E0122 14:00:50.529178 1 conn.go:339] Error on socket receive: read tcp 127.0.0.1:6443->127.0.0.1:38640: use of closed network connection
    

if the backend pod dies or is restarted then you can have those errors, is just indicating that the pod you were connected to is no longer available