mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
internal/poll: ensure that newPoolPipe doesn't return a nil pointer
The function could occasionally return a nil pointer as a non-nil interface, confusing the calling code. Fixes #45520 Change-Id: Ifd35613728efa2cee9903177e85d369155074804 Reviewed-on: https://go-review.googlesource.com/c/go/+/309429 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Andy Pan <panjf2000@gmail.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
2fa7163b06
commit
8b859be9c3
2 changed files with 17 additions and 4 deletions
|
|
@ -169,9 +169,10 @@ func newPoolPipe() interface{} {
|
||||||
// Discard the error which occurred during the creation of pipe buffer,
|
// Discard the error which occurred during the creation of pipe buffer,
|
||||||
// redirecting the data transmission to the conventional way utilizing read() + write() as a fallback.
|
// redirecting the data transmission to the conventional way utilizing read() + write() as a fallback.
|
||||||
p := newPipe()
|
p := newPipe()
|
||||||
if p != nil {
|
if p == nil {
|
||||||
runtime.SetFinalizer(p, destroyPipe)
|
return nil
|
||||||
}
|
}
|
||||||
|
runtime.SetFinalizer(p, destroyPipe)
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,13 +75,19 @@ func TestSplicePipePool(t *testing.T) {
|
||||||
func BenchmarkSplicePipe(b *testing.B) {
|
func BenchmarkSplicePipe(b *testing.B) {
|
||||||
b.Run("SplicePipeWithPool", func(b *testing.B) {
|
b.Run("SplicePipeWithPool", func(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
p, _, _ := poll.GetPipe()
|
p, _, err := poll.GetPipe()
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
poll.PutPipe(p)
|
poll.PutPipe(p)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
b.Run("SplicePipeWithoutPool", func(b *testing.B) {
|
b.Run("SplicePipeWithoutPool", func(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
p := poll.NewPipe()
|
p := poll.NewPipe()
|
||||||
|
if p == nil {
|
||||||
|
b.Skip("newPipe returned nil")
|
||||||
|
}
|
||||||
poll.DestroyPipe(p)
|
poll.DestroyPipe(p)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -90,7 +96,10 @@ func BenchmarkSplicePipe(b *testing.B) {
|
||||||
func BenchmarkSplicePipePoolParallel(b *testing.B) {
|
func BenchmarkSplicePipePoolParallel(b *testing.B) {
|
||||||
b.RunParallel(func(pb *testing.PB) {
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
for pb.Next() {
|
for pb.Next() {
|
||||||
p, _, _ := poll.GetPipe()
|
p, _, err := poll.GetPipe()
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
poll.PutPipe(p)
|
poll.PutPipe(p)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -100,6 +109,9 @@ func BenchmarkSplicePipeNativeParallel(b *testing.B) {
|
||||||
b.RunParallel(func(pb *testing.PB) {
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
for pb.Next() {
|
for pb.Next() {
|
||||||
p := poll.NewPipe()
|
p := poll.NewPipe()
|
||||||
|
if p == nil {
|
||||||
|
b.Skip("newPipe returned nil")
|
||||||
|
}
|
||||||
poll.DestroyPipe(p)
|
poll.DestroyPipe(p)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue