{"record":{"id":"8d3d30ac7182e7bf","repo":"GoogleContainerTools/skaffold","slug":"port-forwarding-v-got-terminated-output-s","errorCode":null,"errorMessage":"port forwarding %v got terminated: output: %s","messagePattern":"port forwarding (.+?) got terminated: output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/skaffold/kubernetes/portforward/kubectl_forwarder.go","lineNumber":167,"sourceCode":"\t\t\ttime.Sleep(500 * time.Millisecond)\n\t\t\tcontinue\n\t\t}\n\n\t\t// Kill kubectl on port forwarding error logs\n\t\tgo k.monitorLogs(ctx, &buf, cmd, pfe, errChan)\n\t\tif err := cmd.Wait(); err != nil {\n\t\t\tif ctx.Err() == context.Canceled {\n\t\t\t\tlog.Entry(ctx).Debugf(\"terminated %v due to context cancellation\", pfe)\n\t\t\t\treturn\n\t\t\t}\n\t\t\t// To make sure that the log monitor gets cleared up\n\t\t\tcancel()\n\n\t\t\ts := buf.String()\n\t\t\tlog.Entry(ctx).Debugf(\"port forwarding %v got terminated: %s, output: %s\", pfe, err, s)\n\t\t\tif !strings.Contains(s, \"address already in use\") {\n\t\t\t\tselect {\n\t\t\t\tcase errChan <- fmt.Errorf(\"port forwarding %v got terminated: output: %s\", pfe, s):\n\t\t\t\tdefault:\n\t\t\t\t}\n\t\t\t}\n\t\t\ttime.Sleep(500 * time.Millisecond)\n\t\t}\n\t}\n}\n\nfunc portForwardArgs(ctx context.Context, kubeContext string, pfe *portForwardEntry) []string {\n\targs := []string{\"--pod-running-timeout\", \"1s\", \"--namespace\", pfe.resource.Namespace}\n\n\t_, disableServiceForwarding := os.LookupEnv(\"SKAFFOLD_DISABLE_SERVICE_FORWARDING\")\n\tswitch {\n\tcase pfe.resource.Type == \"service\" && !disableServiceForwarding:\n\t\t// Services need special handling: https://github.com/GoogleContainerTools/skaffold/issues/4522\n\t\tpodName, remotePort, err := findNewestPodForSvc(ctx, kubeContext, pfe.resource.Namespace, pfe.resource.Name, pfe.resource.Port)\n\t\tif err == nil {\n\t\t\targs = append(args, fmt.Sprintf(\"pod/%s\", podName), fmt.Sprintf(\"%d:%d\", pfe.localPort, remotePort))","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/kubernetes/portforward/kubectl_forwarder.go#L149-L185","documentation":"The forward loop detects that its kubectl port-forward process terminated (scanning output or cmd.Wait error). It logs the buffered kubectl output and, unless the output contains \"address already in use\" (a transient condition the loop retries), it sends this error on errChan without blocking. It means the port-forward tunnel to the pod died and will be re-established by the forwarder's retry loop.","triggerScenarios":"kubectl port-forward process exits: pod restarted/deleted during port-forward, network drop, connection to the pod refused, context timeout/cancellation propagated, or kubectl binary failure.","commonSituations":"Pod crashes or gets rescheduled while dev-loop is running; cluster node reboot; VPN/network interruption; target pod's container port stops listening.","solutions":["Check the `output:` portion of the message for kubectl's actual failure reason (e.g. connection refused, pod not found)","Verify the target pod is running: kubectl get pod <pod> -n <ns>","If the pod was restarted, the forwarder typically retries automatically — wait or restart skaffold dev","Check network/VPN stability to the cluster; transient drops kill the tunnel"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// verify the target pod is ready before initiating the port-forward\npod, err := clientset.CoreV1().Pods(ns).Get(ctx, podName, metav1.GetOptions{})\nif err != nil || pod.Status.Phase != corev1.PodRunning {\n\treturn fmt.Errorf(\"pod %s not ready for port-forward\", podName)\n}","typeGuard":null,"tryCatchPattern":"errChan := make(chan error, 1)\n// forwarder sends termination errors here non-blocking\nselect {\ncase err := <-errChan:\n\tif strings.Contains(err.Error(), \"got terminated\") {\n\t\t// forwarder retries automatically; log and wait for re-establishment\n\t}\ncase <-ctx.Done():\n}","preventionTips":["Keep the cluster network/VPN stable during long dev sessions","Avoid deleting/rescheduling the target pod while port-forwards are active","Monitor pod restarts (kubectl get pods -w) during dev loops","Ignore transient \"address already in use\" variants — the forwarder retries those itself"],"tags":["port-forwarding","kubernetes","network"],"backgroundTag":"port-forward-terminated","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}