[#605] Fix panic when payload discard
Some checks failed
/ DCO (pull_request) Successful in 30s
/ Vulncheck (pull_request) Successful in 1m7s
/ Builds (pull_request) Successful in 1m31s
/ Lint (pull_request) Successful in 2m4s
/ Tests (pull_request) Successful in 1m8s
/ OCI image (pull_request) Successful in 2m10s
/ Builds (push) Has been cancelled
/ OCI image (push) Has been cancelled
/ Lint (push) Has been cancelled
/ Vulncheck (push) Has been cancelled
/ Tests (push) Has been cancelled
Some checks failed
/ DCO (pull_request) Successful in 30s
/ Vulncheck (pull_request) Successful in 1m7s
/ Builds (pull_request) Successful in 1m31s
/ Lint (pull_request) Successful in 2m4s
/ Tests (pull_request) Successful in 1m8s
/ OCI image (pull_request) Successful in 2m10s
/ Builds (push) Has been cancelled
/ OCI image (push) Has been cancelled
/ Lint (push) Has been cancelled
/ Vulncheck (push) Has been cancelled
/ Tests (push) Has been cancelled
Signed-off-by: Roman Loginov <r.loginov@yadro.com>
This commit is contained in:
parent
250538a9b4
commit
e7a8d4bdaf
3 changed files with 29 additions and 5 deletions
|
@ -4,6 +4,11 @@ This document outlines major changes between releases.
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.32.2] - 2025-01-27
|
||||
|
||||
### Fixed
|
||||
- Fix panic when payload discard (#605)
|
||||
|
||||
## [0.32.1] - 2025-01-17
|
||||
|
||||
### Fixed
|
||||
|
@ -400,4 +405,5 @@ To see CHANGELOG for older versions, refer to https://github.com/nspcc-dev/neofs
|
|||
[0.31.3]: https://git.frostfs.info/TrueCloudLab/frostfs-s3-gw/compare/v0.31.2...v0.31.3
|
||||
[0.32.0]: https://git.frostfs.info/TrueCloudLab/frostfs-s3-gw/compare/v0.31.3...v0.32.0
|
||||
[0.32.1]: https://git.frostfs.info/TrueCloudLab/frostfs-s3-gw/compare/v0.32.0...v0.32.1
|
||||
[Unreleased]: https://git.frostfs.info/TrueCloudLab/frostfs-s3-gw/compare/v0.32.1...master
|
||||
[0.32.2]: https://git.frostfs.info/TrueCloudLab/frostfs-s3-gw/compare/v0.32.1...v0.32.2
|
||||
[Unreleased]: https://git.frostfs.info/TrueCloudLab/frostfs-s3-gw/compare/v0.32.2...master
|
|
@ -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…
Reference in a new issue