2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-30 08:44:02 +00:00

s3: Make sure to return connection token

This commit is contained in:
Alexander Neumann 2017-02-10 20:49:37 +01:00
parent 64165ea4c8
commit 7a0303f7ae

View File

@ -155,11 +155,16 @@ func (be *s3) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, er
objName := be.s3path(h) objName := be.s3path(h)
// get token for connection
<-be.connChan <-be.connChan
obj, err := be.client.GetObject(be.bucketname, objName) obj, err := be.client.GetObject(be.bucketname, objName)
if err != nil { if err != nil {
debug.Log(" err %v", err) debug.Log(" err %v", err)
// return token
be.connChan <- struct{}{}
return nil, errors.Wrap(err, "client.GetObject") return nil, errors.Wrap(err, "client.GetObject")
} }
@ -170,12 +175,18 @@ func (be *s3) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, er
_, err = obj.Seek(offset, 0) _, err = obj.Seek(offset, 0)
if err != nil { if err != nil {
_ = obj.Close() _ = obj.Close()
// return token
be.connChan <- struct{}{}
return nil, errors.Wrap(err, "obj.Seek") return nil, errors.Wrap(err, "obj.Seek")
} }
rd := wrapReader{ rd := wrapReader{
ReadCloser: obj, ReadCloser: obj,
f: func() { f: func() {
debug.Log("Close()")
// return token
be.connChan <- struct{}{} be.connChan <- struct{}{}
}, },
} }
@ -183,6 +194,7 @@ func (be *s3) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, er
} }
defer func() { defer func() {
// return token
be.connChan <- struct{}{} be.connChan <- struct{}{}
}() }()