endpoint: fix incorrect early release of maxConcurrentZFSSendSemaphore

fixes #274
This commit is contained in:
Christian Schwarz
2020-02-17 22:53:49 +01:00
parent 0eb7032735
commit b8abba6f55
2 changed files with 24 additions and 3 deletions
+12 -1
View File
@@ -198,7 +198,11 @@ func (s *Sender) Send(ctx context.Context, r *pdu.SendReq) (*pdu.SendRes, zfs.St
if err != nil {
return nil, nil, err
}
defer guard.Release()
defer func(guardp **semaphore.AcquireGuard) {
if *guardp != nil {
(*guardp).Release()
}
}(&guard)
si, err := zfs.ZFSSendDry(ctx, sendArgs)
if err != nil {
@@ -255,6 +259,13 @@ func (s *Sender) Send(ctx context.Context, r *pdu.SendReq) (*pdu.SendRes, zfs.St
if err != nil {
return nil, nil, errors.Wrap(err, "zfs send failed")
}
// defer releasing guard until streamCopier is closed
streamCopier.SetPostCloseCallback(func(_ error) {
guard.Release()
})
guard = nil
return res, streamCopier, nil
}