From 8a3197c5a563d9f7db7a1b4669beff4f3985b6ea Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Wed, 4 Jul 2018 16:29:04 +0800 Subject: [PATCH] add lock on body close --- data_provider.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/data_provider.go b/data_provider.go index cb7e2e5..b53ec1c 100644 --- a/data_provider.go +++ b/data_provider.go @@ -27,8 +27,8 @@ type dataProvider struct { func (dp *dataProvider) Read(buf []byte) (n int, err error) { dp.lock.Lock() defer dp.lock.Unlock() - n, err = dp.buf.Read(buf) + n, err = dp.buf.Read(buf) if err != nil && !dp.closed { return 0, errAgain } @@ -95,11 +95,8 @@ func (bp *bodyProvider) Write(buf []byte) (int, error) { // Close end to provide data func (bp *bodyProvider) Close() error { - /* - if c, ok := bp.w.(io.Closer); ok{ - return c.Close() - } - */ + bp.lock.Lock() + defer bp.lock.Unlock() bp.closed = true return nil }