From: qydysky Date: Mon, 31 Jul 2023 08:28:41 +0000 (+0800) Subject: fix X-Git-Tag: v0.28.0+202307317681ef2 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=7681ef24197fc2faee99ef140663e4e8d0b8ba17;p=part%2F.git fix --- diff --git a/io/io.go b/io/io.go index 0285fe1..e3ea2a1 100644 --- 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; { diff --git a/reqf/Reqf.go b/reqf/Reqf.go index da11e22..39a7e02 100644 --- a/reqf/Reqf.go +++ b/reqf/Reqf.go @@ -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() diff --git a/web/Web_test.go b/web/Web_test.go index 40e327a..e15ee1d 100644 --- a/web/Web_test.go +++ b/web/Web_test.go @@ -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)