ClosedChannelException in Jenkins with Kubernetes Plugin

At some points I have run into an error from my pipeline that have made no sense.

Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from
at hudson.remoting.Channel.attachCallSiteStackTrace(
at hudson.FilePath.act(
at hudson.FilePath.act(
at hudson.plugins.cobertura.CoberturaPublisher.perform(
at org.jenkinsci.plugins.workflow.steps.CoreStep$
at org.jenkinsci.plugins.workflow.steps.CoreStep$
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$
at java.util.concurrent.Executors$
Caused: hudson.remoting.RequestAbortedException
at hudson.remoting.Request.abort(
at hudson.remoting.Channel.terminate(
at org.jenkinsci.remoting.protocol.impl.ChannelApplicationLayer.onReadClosed(
at org.jenkinsci.remoting.protocol.ApplicationLayer.onRecvClosed(
at org.jenkinsci.remoting.protocol.ProtocolStack$Ptr.onRecvClosed(
at org.jenkinsci.remoting.protocol.FilterLayer.onRecvClosed(
at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.onRecvClosed(
at org.jenkinsci.remoting.protocol.ProtocolStack$Ptr.onRecvClosed(
at org.jenkinsci.remoting.protocol.NetworkLayer.onRecvClosed(
at org.jenkinsci.remoting.protocol.impl.NIONetworkLayer.ready(
at org.jenkinsci.remoting.protocol.IOHub$
at jenkins.util.ContextResettingExecutorService$
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$
Finished: FAILURE

No amount of googling helped me figure it out. After about four hours, I finally noticed that the pod in Kubernetes Dashboard UI said that the status of the pod was Terminated: OOMKill.

This led me to the article about how Kubernetes deals with pods that exceed the limits of its resources. In this particular case, the CoberturaPublisher that creates the coverage report for unit tests, has exceeded the limits for the Jenkins slave pod. Kubernetes kills the pod and Jenkins gets a severed connection which manifests itself as the error above.

The fix for this is simple, just increase the resources that are allocated for the pods. If you are using helm to configure Jenkins then add resources to Master and Agent. The amount depends on your needs, I gave my agent more resources so that the builds would complete quicker.

Enabled: true
ImageTag: alpine
cpu: "1000m"
memory: "1024Mi"
cpu: "2000m"
memory: "2048Mi"