http2 throws custom error Content-Length shorter handle it (#7334)

We should internally handle when http2 input stream has smaller
content than its content-length header

Upstream issue reported https://github.com/golang/go/issues/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.
master
Harshavardhana 6 years ago committed by GitHub
parent f4879ed96d
commit 0b96ad4fdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      cmd/api-errors.go

@ -21,6 +21,7 @@ import (
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"net/http" "net/http"
"strings"
"github.com/Azure/azure-sdk-for-go/storage" "github.com/Azure/azure-sdk-for-go/storage"
"github.com/aliyun/aliyun-oss-go-sdk/oss" "github.com/aliyun/aliyun-oss-go-sdk/oss"
@ -1641,11 +1642,25 @@ func toAPIErrorCode(ctx context.Context, err error) (apiErr APIErrorCode) {
case crypto.Error: case crypto.Error:
apiErr = ErrObjectTampered apiErr = ErrObjectTampered
default: default:
apiErr = ErrInternalError var ie, iw int
// Make sure to log the errors which we cannot translate // This work-around is to handle the issue golang/go#30648
// to a meaningful S3 API errors. This is added to aid in if _, ferr := fmt.Fscanf(strings.NewReader(err.Error()),
// debugging unexpected/unhandled errors. "request declared a Content-Length of %d but only wrote %d bytes",
logger.LogIf(ctx, err) &ie, &iw); ferr != nil {
apiErr = ErrInternalError
// Make sure to log the errors which we cannot translate
// to a meaningful S3 API errors. This is added to aid in
// debugging unexpected/unhandled errors.
logger.LogIf(ctx, err)
} else if ie > iw {
apiErr = ErrIncompleteBody
} else {
apiErr = ErrInternalError
// Make sure to log the errors which we cannot translate
// to a meaningful S3 API errors. This is added to aid in
// debugging unexpected/unhandled errors.
logger.LogIf(ctx, err)
}
} }
return apiErr return apiErr

Loading…
Cancel
Save