Skip to content

Commit 121b50e

Browse files
http2 throws custom error Content-Length shorter handle it
We should internally handle when http2 input stream has smaller content than its content-length header Upstream issue reported golang/go#30648 This a change which we need to handle internally until Go fixes it correctly, till now our code doesn't expect a custom error to be returned.
1 parent f4879ed commit 121b50e

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

cmd/api-errors.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/xml"
2222
"fmt"
2323
"net/http"
24+
"strings"
2425

2526
"github.com/Azure/azure-sdk-for-go/storage"
2627
"github.com/aliyun/aliyun-oss-go-sdk/oss"
@@ -1641,11 +1642,24 @@ func toAPIErrorCode(ctx context.Context, err error) (apiErr APIErrorCode) {
16411642
case crypto.Error:
16421643
apiErr = ErrObjectTampered
16431644
default:
1644-
apiErr = ErrInternalError
1645-
// Make sure to log the errors which we cannot translate
1646-
// to a meaningful S3 API errors. This is added to aid in
1647-
// debugging unexpected/unhandled errors.
1648-
logger.LogIf(ctx, err)
1645+
var ie, iw int
1646+
if _, ferr := fmt.Fscanf(strings.NewReader(err.Error()),
1647+
"request declared a Content-Length of %d but only wrote %d bytes",
1648+
&ie, &iw); ferr != nil {
1649+
apiErr = ErrInternalError
1650+
// Make sure to log the errors which we cannot translate
1651+
// to a meaningful S3 API errors. This is added to aid in
1652+
// debugging unexpected/unhandled errors.
1653+
logger.LogIf(ctx, err)
1654+
} else if ie > iw {
1655+
apiErr = ErrIncompleteBody
1656+
} else {
1657+
apiErr = ErrInternalError
1658+
// Make sure to log the errors which we cannot translate
1659+
// to a meaningful S3 API errors. This is added to aid in
1660+
// debugging unexpected/unhandled errors.
1661+
logger.LogIf(ctx, err)
1662+
}
16491663
}
16501664

16511665
return apiErr

0 commit comments

Comments
 (0)