k8z icon indicating copy to clipboard operation
k8z copied to clipboard

use of closed network connection

Open qyk1995 opened this issue 2 years ago • 0 comments

当我成功连接到k8s集群之后,发送一个请求会出现下面错误: { "type": "stdout", "data": "exit\r\n", "cols": 0, "rows": 0 } 和 E0727 11:09:46.370144 29472 v2.go:104] write tcp xx.xx.xx:61184->xx.xx.xx.xx:443: use of closed network connection

自己的代码: conn, err :=websocket.Upgrade(c.Writer,` c.Request, nil, 1024, 1024) if err != nil { fmt.Println("Upgrade", err) c.AbortWithStatusJSON(http.StatusOK, gin.H{"code": http.StatusInternalServerError, "msg": err.Error()}) return }

// 通过 集群名称获取config
config, err := common.Getk8sclusterConfig(params.ClusterName)
config.ContentConfig.GroupVersion = &v1.Unversioned
config.ContentConfig.NegotiatedSerializer = scheme.Codecs

if err != nil {
	elog.Errorw("ContainerExec", "config", err)
	// c.JSONE(core.CodeErr, "cluster not found", nil)
	return
}
wsTransport := transport.NewWSTransport(conn)

tml, err := terminal.NewWebTerminal(config, params.Namespace, params.PodName, params.ContainerName, wsTransport)
if err != nil {
	elog.Errorw("ContainerExec", "terminal", err)
	_, _ = wsTransport.Write([]byte("连接终端失败,该Pod可能已经下线\n" + err.Error()))
	return
}
err = tml.Run()
if err != nil {
	elog.Errorw("ContainerExec", "run", err)
	_, _ = wsTransport.Write([]byte("连接终端失败:" + err.Error()))
	return
}

`

qyk1995 avatar Jul 27 '23 03:07 qyk1995