1 Star 0 Fork 43

刘铭/kubernetes

forked from src-openEuler/kubernetes 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0008-kubelet-fix-websocket-reference-nil-pointer.patch 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
From 760129610e5b54d548247490899a8595cea2d5b8 Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <[email protected]>
Date: Mon, 31 Oct 2022 17:15:51 +0800
Subject: [PATCH] kubelet fix websocket reference nul pointer
Signed-off-by: zhangxiaoyu <[email protected]>
---
.../cri/streaming/remotecommand/proxy.go | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/pkg/kubelet/cri/streaming/remotecommand/proxy.go b/pkg/kubelet/cri/streaming/remotecommand/proxy.go
index 76222d90..f21629af 100644
--- a/pkg/kubelet/cri/streaming/remotecommand/proxy.go
+++ b/pkg/kubelet/cri/streaming/remotecommand/proxy.go
@@ -169,14 +169,23 @@ func connectBackend(addr, subprotocol string, r *http.Request) (*websocket.Conn,
websocket.DefaultDialer.ReadBufferSize = 128 * 1024
websocket.DefaultDialer.WriteBufferSize = 128 * 1024
ws, resp, err := websocket.DefaultDialer.Dial(addr, h)
- if err != nil {
+ if err == nil {
+ return ws, nil
+ }
+ msg := fmt.Errorf("dial failed: %v, response Body is nil", err)
+ if resp != nil && resp.Body != nil {
+ defer func() {
+ //websocket buffer size maybe not enough and cause panic
+ if e := recover(); e != nil {
+ msg = fmt.Errorf("dial failed: %v, response panic %v", err, e)
+ }
+ resp.Body.Close()
+ }()
var body bytes.Buffer
body.ReadFrom(resp.Body)
- defer resp.Body.Close()
- msg := fmt.Errorf("dial failed: %v, response is: %v", err, body.String())
- return nil, msg
+ msg = fmt.Errorf("dial failed: %v, response is: %v", err, body.String())
}
- return ws, nil
+ return nil, msg
}
type rwc struct {
--
2.25.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liuming3/kubernetes.git
[email protected]:liuming3/kubernetes.git
liuming3
kubernetes
kubernetes
master

搜索帮助