[#605] Fix panic when payload discard
Signed-off-by: Roman Loginov <r.loginov@yadro.com>
This commit is contained in:
parent
5842f5bad5
commit
826e26544e
2 changed files with 22 additions and 4 deletions
|
@ -525,10 +525,7 @@ func (n *Layer) objectPutAndHash(ctx context.Context, prm frostfs.PrmObjectCreat
|
|||
})
|
||||
res, err := n.frostFS.CreateObject(ctx, prm)
|
||||
if err != nil {
|
||||
if _, errDiscard := io.Copy(io.Discard, prm.Payload); errDiscard != nil {
|
||||
n.reqLogger(ctx).Warn(logs.FailedToDiscardPutPayloadProbablyGoroutineLeaks, zap.Error(errDiscard))
|
||||
}
|
||||
|
||||
n.payloadDiscard(ctx, prm.Payload)
|
||||
return nil, err
|
||||
}
|
||||
return &data.CreatedObjectInfo{
|
||||
|
@ -540,6 +537,14 @@ func (n *Layer) objectPutAndHash(ctx context.Context, prm frostfs.PrmObjectCreat
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (n *Layer) payloadDiscard(ctx context.Context, payload io.Reader) {
|
||||
if payload != nil {
|
||||
if _, errDiscard := io.Copy(io.Discard, payload); errDiscard != nil {
|
||||
n.reqLogger(ctx).Warn(logs.FailedToDiscardPutPayloadProbablyGoroutineLeaks, zap.Error(errDiscard))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type logWrapper struct {
|
||||
log *zap.Logger
|
||||
}
|
||||
|
|
|
@ -49,3 +49,16 @@ func TestGoroutinesDontLeakInPutAndHash(t *testing.T) {
|
|||
require.ErrorIs(t, err, expErr)
|
||||
require.Empty(t, payload.Len(), "body must be read out otherwise goroutines can leak in wrapReader")
|
||||
}
|
||||
|
||||
func TestNilPayloadPutAndHash(t *testing.T) {
|
||||
tc := prepareContext(t)
|
||||
prm := frostfs.PrmObjectCreate{
|
||||
Filepath: tc.obj,
|
||||
Payload: nil,
|
||||
}
|
||||
|
||||
expErr := errors.New("some error")
|
||||
tc.testFrostFS.SetObjectPutError(tc.obj, expErr)
|
||||
_, err := tc.layer.objectPutAndHash(tc.ctx, prm, tc.bktInfo)
|
||||
require.ErrorIs(t, err, expErr)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue