测试一段代码,发现Buffer包偶尔会Panic,记录一下:
Test Panicked
runtime error: slice bounds out of range
/usr/local/Cellar/go/1.11.2/libexec/src/runtime/panic.go:513
Full Stack Trace
/usr/local/Cellar/go/1.11.2/libexec/src/runtime/panic.go:513 +0x1b9
bytes.(*Buffer).readSlice(0xc000234030, 0x104d30a, 0x1ba1b80, 0xc0002b1312, 0x2, 0xc0002b0140, 0xc000001980)
/usr/local/Cellar/go/1.11.2/libexec/src/bytes/buffer.go:418 +0x101
bytes.(*Buffer).ReadString(0xc000234030, 0xc00005c00a, 0xc00005c040, 0x1, 0x16513a0, 0xc00005c040)
/usr/local/Cellar/go/1.11.2/libexec/src/bytes/buffer.go:437 +0x38
git-biz.360es.cn/connectors/utils/protocol/ssh.(*SSHClient).inputFlag(0xc000234000, 0x16566c0, 0x1bbb388)
/Users/dongchaofeng/dongchaofeng/src/git-biz.360es.cn/connectors/utils/protocol/ssh/ssh.go:122 +0xec
git-biz.360es.cn/connectors/utils/protocol/ssh.glob..func1.6()
/Users/dongchaofeng/dongchaofeng/src/git-biz.360es.cn/connectors/utils/protocol/ssh/ssh_test.go:133 +0x302
git-biz.360es.cn/connectors/utils/vendor/github.com/onsi/ginkgo/internal/leafnodes.(*runner).runSync(0xc00009cd20, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/Users/dongchaofeng/dongchaofeng/src/git-biz.360es.cn/connectors/utils/protocol/ssh/ssh_test.go:16 +0xa2
testing.tRunner(0xc000206100, 0x15ea268)
/usr/local/Cellar/go/1.11.2/libexec/src/testing/testing.go:827 +0xbf
created by testing.(*T).Run
/usr/local/Cellar/go/1.11.2/libexec/src/testing/testing.go:878 +0x353
有疑问加站长微信联系(非本文作者)