]> 127.0.0.1 Git - part/.git/commitdiff
add v0.28.0+20230604bee01ff
authorqydysky <qydysky@foxmail.com>
Sun, 4 Jun 2023 23:15:58 +0000 (07:15 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 4 Jun 2023 23:15:58 +0000 (07:15 +0800)
io/io.go

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