Skip to content

Commit 4caa0b1

Browse files
committed
fix for cch123#45
1 parent 375f30d commit 4caa0b1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

io.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,17 @@ const (
394394
)
395395
// io.Copy 该场景下内部调用 splice syscall, 感兴趣的自行查看源码
396396
func gosplice(src, dst net.Conn) {
397+
defer src.Close()
398+
defer dst.Close()
397399
go func() {
398400
io.Copy(src, dst)
399401
}()
400402
io.Copy(dst, src)
401403
}
402404

403405
func normal(src, dst net.Conn) {
406+
defer src.Close()
407+
defer dst.Close()
404408
var bts []byte = p.Get().([]byte)
405409
var bts2 []byte = p.Get().([]byte)
406410
defer p.Put(bts)
@@ -475,7 +479,6 @@ func TestMain(m *testing.M) {
475479
if err != nil {
476480
continue
477481
}
478-
defer n.Close()
479482
remote, err := net.DialTCP("tcp4", &net.TCPAddr{
480483
IP: net.ParseIP("0.0.0.0"), Port: 0,
481484
}, &net.TCPAddr{
@@ -500,7 +503,6 @@ func TestMain(m *testing.M) {
500503
if err != nil {
501504
continue
502505
}
503-
defer n.Close()
504506
remote, err := net.DialTCP("tcp4", &net.TCPAddr{
505507
IP: net.ParseIP("0.0.0.0"), Port: 0,
506508
}, &net.TCPAddr{
@@ -531,6 +533,7 @@ func BenchmarkNormalReadWrite(b *testing.B) {
531533
if err == nil && res.StatusCode == 200 {
532534
atomic.AddUint32(&success, 1)
533535
}
536+
c.CloseIdleConnections()
534537
}
535538
b.Logf("test:%s,total: %d,rate: %.2f%%\n", b.Name(), total, float64(success*100/total))
536539
}
@@ -552,6 +555,7 @@ func BenchmarkGoSplice(b *testing.B) {
552555
if err == nil && res.StatusCode == 200 {
553556
atomic.AddUint32(&success, 1)
554557
}
558+
c.CloseIdleConnections()
555559
}
556560
b.Logf("test:%s, total: %d, success rate: %.2f%%\n", b.Name(), total, float64(success*100/total))
557561
}

0 commit comments

Comments
 (0)