Permalink
Browse files

Fix proxied+stored readcloser + alt close

  • Loading branch information...
1 parent baafbbe commit b5e045c75cf7295c5cb50424db1f3b127087b781 @dustin dustin committed Jan 22, 2014
Showing with 19 additions and 2 deletions.
  1. +19 −2 blobs.go
View
@@ -17,6 +17,7 @@ import (
cb "github.com/couchbaselabs/go-couchbase"
"github.com/dustin/gomemcached"
"github.com/dustin/gomemcached/client"
+ "sethwklein.net/go/errutil"
)
type BlobOwnership struct {
@@ -704,6 +705,22 @@ func openBlob(oid string, localOnly bool) (io.ReadCloser, error) {
return openRemote(oid, bo.Length, *cachePercentage, nl)
}
+type readerClosers struct {
+ r io.Reader
+ closers []io.Closer
+}
+
+func (r *readerClosers) Read(b []byte) (int, error) {
+ return r.r.Read(b)
+}
+
+func (r *readerClosers) Close() (err error) {
+ for _, c := range r.closers {
+ errutil.AppendCall(&err, c.Close)
+ }
+ return
+}
+
func openRemote(oid string, l int64, cachePerc int, nl NodeList) (io.ReadCloser, error) {
for _, sid := range nl {
resp, err := sid.ClientForTransfer(l).Get(sid.BlobURL(oid))
@@ -726,11 +743,11 @@ func openRemote(oid string, l int64, cachePerc int, nl NodeList) (io.ReadCloser,
if !shouldCache {
return resp.Body, nil
}
- defer resp.Body.Close()
hw, err := NewHashRecord(*root, oid)
r := io.TeeReader(resp.Body, hw)
- return &hwFinisher{r, hw, oid, l}, nil
+ rv := &hwFinisher{r, hw, oid, l}
+ return &readerClosers{rv, []io.Closer{rv, resp.Body}}, nil
}
return nil, fmt.Errorf("couldn't get ob from any of %v", nl)
}

0 comments on commit b5e045c

Please sign in to comment.