]> 127.0.0.1 Git - part/.git/commitdiff
fix v0.28.0+2023060658d1b57
authorqydysky <qydysky@foxmail.com>
Tue, 6 Jun 2023 10:52:48 +0000 (18:52 +0800)
committerqydysky <qydysky@foxmail.com>
Tue, 6 Jun 2023 10:52:48 +0000 (18:52 +0800)
io/io.go

index 1bfc7c4be6297d42d694fa1953aa3f8da698e239..c1ad7b6e6166abf84bd48022932a023e93653d3a 100644 (file)
--- a/io/io.go
+++ b/io/io.go
@@ -76,7 +76,7 @@ func WithCtxTO(ctx context.Context, callTree string, to time.Duration, w io.Writ
                for {
                        select {
                        case <-ctx.Done():
-                               if old := chanw.Load(); old < 0 {
+                               if old := chanw.Load(); old == -1 {
                                        return
                                } else if now := time.Now(); old > 0 && now.Unix()-old > int64(to.Seconds()) {
                                        if old != 0 {
@@ -84,14 +84,16 @@ func WithCtxTO(ctx context.Context, callTree string, to time.Duration, w io.Writ
                                        }
                                } else {
                                        time.AfterFunc(to, func() {
-                                               if old, now := chanw.Load(), time.Now(); old != 0 && now.Unix()-old > int64(to.Seconds()) {
+                                               if old := chanw.Load(); old == -1 {
+                                                       return
+                                               } else if now := time.Now(); old > 0 && now.Unix()-old > int64(to.Seconds()) {
                                                        panicf[0](fmt.Sprintf("write blocking after close %vs > %v, goruntime leak \n%v", now.Unix()-old, to, callTree))
                                                }
                                        })
                                }
                                return
                        case now := <-timer.C:
-                               if old := chanw.Load(); old < 0 {
+                               if old := chanw.Load(); old == -1 {
                                        return
                                } else if old > 0 && now.Unix()-old > int64(to.Seconds()) {
                                        panicf[0](fmt.Sprintf("write blocking after rw %vs > %v, goruntime leak \n%v", now.Unix()-old, to, callTree))