client-go icon indicating copy to clipboard operation
client-go copied to clipboard

GetLogs function hangs after 4 hours

Open avneradania1 opened this issue 2 years ago • 0 comments

the below is a code to tail logs for specific pod/container. when tailing pod, after 4 hours exactly, it hangs and break loop of Scan() and continue while pod still running. In addition, kubectl logs -f POD -n NS also stopped after 4 hours. Any idea, someone?

	
       rs, err := api.clientset.CoreV1().Pods(api.ns).GetLogs(api.podName, &v1.PodLogOptions{
		Container: api.options.containerName,
		Follow: true,

	}).Stream(context.TODO())
	if err != nil {
		return err
	}
	defer rs.Close()
	sc := bufio.NewScanner(rs)

	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()

	for sc.Scan() {
		f.Write([]byte(sc.Text() + "\n"))
		f.Flush()
	}

avneradania1 avatar Aug 25 '22 06:08 avneradania1