]> 127.0.0.1 Git - part/.git/commitdiff
fix v0.28.0+202307317681ef2
authorqydysky <qydysky@foxmail.com>
Mon, 31 Jul 2023 08:28:41 +0000 (16:28 +0800)
committerqydysky <qydysky@foxmail.com>
Mon, 31 Jul 2023 08:28:41 +0000 (16:28 +0800)
io/io.go
reqf/Reqf.go
web/Web_test.go

index 0285fe127f8c59cd0c71bf5ee522f454d184031b..e3ea2a1178b4cc9486e9048c18acaeb1a441723f 100644 (file)
--- a/io/io.go
+++ b/io/io.go
@@ -149,7 +149,7 @@ func (t RWC) Close() error {
 // to avoid writer block after ctx done, you should close writer after ctx done
 //
 // call Close() after writer fin
-func WithCtxTO(ctx context.Context, callTree string, to time.Duration, w []io.Writer, r io.Reader, panicf ...func(s string)) io.ReadWriteCloser {
+func WithCtxTO(ctx context.Context, callTree string, to time.Duration, w io.Writer, r io.Reader, panicf ...func(s string)) io.ReadWriteCloser {
        var chanw atomic.Int64
        chanw.Store(time.Now().Unix())
        if len(panicf) == 0 {
@@ -198,9 +198,7 @@ func WithCtxTO(ctx context.Context, callTree string, to time.Duration, w []io.Wr
                        case <-ctx.Done():
                                err = context.Canceled
                        default:
-                               for i := 0; i < len(w); i++ {
-                                       _, err = w[i].Write(p)
-                               }
+                               _, err = w.Write(p)
                                chanw.Store(time.Now().Unix())
                        }
                        return
@@ -222,7 +220,7 @@ var (
 // to avoid writer block after ctx done, you should close writer after ctx done
 //
 // call Close() after writer fin
-func WithCtxCopy(ctx context.Context, callTree string, to time.Duration, w []io.Writer, r io.Reader, panicf ...func(s string)) error {
+func WithCtxCopy(ctx context.Context, callTree string, to time.Duration, w io.Writer, r io.Reader, panicf ...func(s string)) error {
        rwc := WithCtxTO(ctx, callTree, to, w, r, panicf...)
        defer rwc.Close()
        for buf := make([]byte, 2048); true; {
index da11e225f9e1ace783c22c18a6b55b5c8d360efe..39a7e029643b328792d1283be9bfe031c8d6023b 100644 (file)
@@ -273,7 +273,7 @@ func (t *Req) Reqf_1(ctx context.Context, val Rval) (err error) {
        var panicf = func(s string) {
                err = errors.Join(err, errors.New(s))
        }
-       err = errors.Join(err, pio.WithCtxCopy(req.Context(), t.callTree, time.Duration(int(time.Millisecond)*writeLoopTO), ws, resReadCloser, panicf))
+       err = errors.Join(err, pio.WithCtxCopy(req.Context(), t.callTree, time.Duration(int(time.Millisecond)*writeLoopTO), io.MultiWriter(ws...), resReadCloser, panicf))
 
        resp.Body.Close()
 
index 40e327aa34fa2c09e4d9bb214927515ae3a5bd9d..e15ee1d390f947ce11827dca084da58129ab23c2 100644 (file)
@@ -85,7 +85,7 @@ func Test_ClientBlock(t *testing.T) {
 
        m.Store("/to", func(w http.ResponseWriter, r *http.Request) {
                rwc := pio.WithCtxTO(r.Context(), fmt.Sprintf("server handle %v by %v ", r.URL.Path, r.RemoteAddr), time.Second,
-                       []io.Writer{w}, r.Body, func(s string) {
+                       w, r.Body, func(s string) {
                                fmt.Println(s)
                                if !strings.Contains(s, "write blocking after rw 2s > 1s, goruntime leak") {
                                        t.Fatal(s)