mirror of
https://github.com/minio/minio.git
synced 2025-01-25 21:53:16 -05:00
fix: return context error from context reader (#9507)
This commit is contained in:
parent
fea4a1e68e
commit
7b58dcb28c
@ -628,7 +628,7 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h
|
|||||||
bucket := mux.Vars(r)["bucket"]
|
bucket := mux.Vars(r)["bucket"]
|
||||||
|
|
||||||
// To detect if the client has disconnected.
|
// To detect if the client has disconnected.
|
||||||
r.Body = &detectDisconnect{r.Body, r.Context().Done()}
|
r.Body = &contextReader{r.Body, r.Context()}
|
||||||
|
|
||||||
// Require Content-Length to be set in the request
|
// Require Content-Length to be set in the request
|
||||||
size := r.ContentLength
|
size := r.ContentLength
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -106,6 +107,8 @@ func toObjectErr(err error, params ...string) error {
|
|||||||
err = InsufficientWriteQuorum{}
|
err = InsufficientWriteQuorum{}
|
||||||
case io.ErrUnexpectedEOF, io.ErrShortWrite:
|
case io.ErrUnexpectedEOF, io.ErrShortWrite:
|
||||||
err = IncompleteBody{}
|
err = IncompleteBody{}
|
||||||
|
case context.Canceled, context.DeadlineExceeded:
|
||||||
|
err = IncompleteBody{}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -842,16 +843,17 @@ func newS2CompressReader(r io.Reader) io.ReadCloser {
|
|||||||
return pr
|
return pr
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns error if the cancelCh has been closed (indicating that S3 client has disconnected)
|
// Returns error if the context is canceled, indicating
|
||||||
type detectDisconnect struct {
|
// either client has disconnected
|
||||||
|
type contextReader struct {
|
||||||
io.ReadCloser
|
io.ReadCloser
|
||||||
cancelCh <-chan struct{}
|
ctx context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *detectDisconnect) Read(p []byte) (int, error) {
|
func (d *contextReader) Read(p []byte) (int, error) {
|
||||||
select {
|
select {
|
||||||
case <-d.cancelCh:
|
case <-d.ctx.Done():
|
||||||
return 0, io.ErrUnexpectedEOF
|
return 0, d.ctx.Err()
|
||||||
default:
|
default:
|
||||||
return d.ReadCloser.Read(p)
|
return d.ReadCloser.Read(p)
|
||||||
}
|
}
|
||||||
|
@ -1209,7 +1209,7 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req
|
|||||||
}
|
}
|
||||||
|
|
||||||
// To detect if the client has disconnected.
|
// To detect if the client has disconnected.
|
||||||
r.Body = &detectDisconnect{r.Body, r.Context().Done()}
|
r.Body = &contextReader{r.Body, r.Context()}
|
||||||
|
|
||||||
// X-Amz-Copy-Source shouldn't be set for this call.
|
// X-Amz-Copy-Source shouldn't be set for this call.
|
||||||
if _, ok := r.Header[xhttp.AmzCopySource]; ok {
|
if _, ok := r.Header[xhttp.AmzCopySource]; ok {
|
||||||
@ -1958,7 +1958,7 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http
|
|||||||
}
|
}
|
||||||
|
|
||||||
// To detect if the client has disconnected.
|
// To detect if the client has disconnected.
|
||||||
r.Body = &detectDisconnect{r.Body, r.Context().Done()}
|
r.Body = &contextReader{r.Body, r.Context()}
|
||||||
|
|
||||||
// X-Amz-Copy-Source shouldn't be set for this call.
|
// X-Amz-Copy-Source shouldn't be set for this call.
|
||||||
if _, ok := r.Header[xhttp.AmzCopySource]; ok {
|
if _, ok := r.Header[xhttp.AmzCopySource]; ok {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user