Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use of closed network connection #13

Open
qyk1995 opened this issue Jul 27, 2023 · 0 comments
Open

use of closed network connection #13

qyk1995 opened this issue Jul 27, 2023 · 0 comments

Comments

@qyk1995
Copy link

qyk1995 commented Jul 27, 2023

当我成功连接到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
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant