aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/aws/aws-sdk-go/aws/request/request.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/aws/aws-sdk-go/aws/request/request.go')
-rw-r--r--vendor/github.com/aws/aws-sdk-go/aws/request/request.go92
1 files changed, 65 insertions, 27 deletions
diff --git a/vendor/github.com/aws/aws-sdk-go/aws/request/request.go b/vendor/github.com/aws/aws-sdk-go/aws/request/request.go
index 8f2eb3e..e7c9b2b 100644
--- a/vendor/github.com/aws/aws-sdk-go/aws/request/request.go
+++ b/vendor/github.com/aws/aws-sdk-go/aws/request/request.go
@@ -4,6 +4,7 @@ import (
4 "bytes" 4 "bytes"
5 "fmt" 5 "fmt"
6 "io" 6 "io"
7 "net"
7 "net/http" 8 "net/http"
8 "net/url" 9 "net/url"
9 "reflect" 10 "reflect"
@@ -231,6 +232,10 @@ func (r *Request) WillRetry() bool {
231 return r.Error != nil && aws.BoolValue(r.Retryable) && r.RetryCount < r.MaxRetries() 232 return r.Error != nil && aws.BoolValue(r.Retryable) && r.RetryCount < r.MaxRetries()
232} 233}
233 234
235func fmtAttemptCount(retryCount, maxRetries int) string {
236 return fmt.Sprintf("attempt %v/%v", retryCount, maxRetries)
237}
238
234// ParamsFilled returns if the request's parameters have been populated 239// ParamsFilled returns if the request's parameters have been populated
235// and the parameters are valid. False is returned if no parameters are 240// and the parameters are valid. False is returned if no parameters are
236// provided or invalid. 241// provided or invalid.
@@ -259,7 +264,18 @@ func (r *Request) SetStringBody(s string) {
259// SetReaderBody will set the request's body reader. 264// SetReaderBody will set the request's body reader.
260func (r *Request) SetReaderBody(reader io.ReadSeeker) { 265func (r *Request) SetReaderBody(reader io.ReadSeeker) {
261 r.Body = reader 266 r.Body = reader
262 r.BodyStart, _ = reader.Seek(0, sdkio.SeekCurrent) // Get the Bodies current offset. 267
268 if aws.IsReaderSeekable(reader) {
269 var err error
270 // Get the Bodies current offset so retries will start from the same
271 // initial position.
272 r.BodyStart, err = reader.Seek(0, sdkio.SeekCurrent)
273 if err != nil {
274 r.Error = awserr.New(ErrCodeSerialization,
275 "failed to determine start of request body", err)
276 return
277 }
278 }
263 r.ResetBody() 279 r.ResetBody()
264} 280}
265 281
@@ -330,16 +346,15 @@ func getPresignedURL(r *Request, expire time.Duration) (string, http.Header, err
330 return r.HTTPRequest.URL.String(), r.SignedHeaderVals, nil 346 return r.HTTPRequest.URL.String(), r.SignedHeaderVals, nil
331} 347}
332 348
333func debugLogReqError(r *Request, stage string, retrying bool, err error) { 349const (
350 notRetrying = "not retrying"
351)
352
353func debugLogReqError(r *Request, stage, retryStr string, err error) {
334 if !r.Config.LogLevel.Matches(aws.LogDebugWithRequestErrors) { 354 if !r.Config.LogLevel.Matches(aws.LogDebugWithRequestErrors) {
335 return 355 return
336 } 356 }
337 357
338 retryStr := "not retrying"
339 if retrying {
340 retryStr = "will retry"
341 }
342
343 r.Config.Logger.Log(fmt.Sprintf("DEBUG: %s %s/%s failed, %s, error %v", 358 r.Config.Logger.Log(fmt.Sprintf("DEBUG: %s %s/%s failed, %s, error %v",
344 stage, r.ClientInfo.ServiceName, r.Operation.Name, retryStr, err)) 359 stage, r.ClientInfo.ServiceName, r.Operation.Name, retryStr, err))
345} 360}
@@ -358,12 +373,12 @@ func (r *Request) Build() error {
358 if !r.built { 373 if !r.built {
359 r.Handlers.Validate.Run(r) 374 r.Handlers.Validate.Run(r)
360 if r.Error != nil { 375 if r.Error != nil {
361 debugLogReqError(r, "Validate Request", false, r.Error) 376 debugLogReqError(r, "Validate Request", notRetrying, r.Error)
362 return r.Error 377 return r.Error
363 } 378 }
364 r.Handlers.Build.Run(r) 379 r.Handlers.Build.Run(r)
365 if r.Error != nil { 380 if r.Error != nil {
366 debugLogReqError(r, "Build Request", false, r.Error) 381 debugLogReqError(r, "Build Request", notRetrying, r.Error)
367 return r.Error 382 return r.Error
368 } 383 }
369 r.built = true 384 r.built = true
@@ -379,7 +394,7 @@ func (r *Request) Build() error {
379func (r *Request) Sign() error { 394func (r *Request) Sign() error {
380 r.Build() 395 r.Build()
381 if r.Error != nil { 396 if r.Error != nil {
382 debugLogReqError(r, "Build Request", false, r.Error) 397 debugLogReqError(r, "Build Request", notRetrying, r.Error)
383 return r.Error 398 return r.Error
384 } 399 }
385 400
@@ -387,12 +402,16 @@ func (r *Request) Sign() error {
387 return r.Error 402 return r.Error
388} 403}
389 404
390func (r *Request) getNextRequestBody() (io.ReadCloser, error) { 405func (r *Request) getNextRequestBody() (body io.ReadCloser, err error) {
391 if r.safeBody != nil { 406 if r.safeBody != nil {
392 r.safeBody.Close() 407 r.safeBody.Close()
393 } 408 }
394 409
395 r.safeBody = newOffsetReader(r.Body, r.BodyStart) 410 r.safeBody, err = newOffsetReader(r.Body, r.BodyStart)
411 if err != nil {
412 return nil, awserr.New(ErrCodeSerialization,
413 "failed to get next request body reader", err)
414 }
396 415
397 // Go 1.8 tightened and clarified the rules code needs to use when building 416 // Go 1.8 tightened and clarified the rules code needs to use when building
398 // requests with the http package. Go 1.8 removed the automatic detection 417 // requests with the http package. Go 1.8 removed the automatic detection
@@ -409,10 +428,10 @@ func (r *Request) getNextRequestBody() (io.ReadCloser, error) {
409 // Related golang/go#18257 428 // Related golang/go#18257
410 l, err := aws.SeekerLen(r.Body) 429 l, err := aws.SeekerLen(r.Body)
411 if err != nil { 430 if err != nil {
412 return nil, awserr.New(ErrCodeSerialization, "failed to compute request body size", err) 431 return nil, awserr.New(ErrCodeSerialization,
432 "failed to compute request body size", err)
413 } 433 }
414 434
415 var body io.ReadCloser
416 if l == 0 { 435 if l == 0 {
417 body = NoBody 436 body = NoBody
418 } else if l > 0 { 437 } else if l > 0 {
@@ -473,13 +492,13 @@ func (r *Request) Send() error {
473 r.AttemptTime = time.Now() 492 r.AttemptTime = time.Now()
474 493
475 if err := r.Sign(); err != nil { 494 if err := r.Sign(); err != nil {
476 debugLogReqError(r, "Sign Request", false, err) 495 debugLogReqError(r, "Sign Request", notRetrying, err)
477 return err 496 return err
478 } 497 }
479 498
480 if err := r.sendRequest(); err == nil { 499 if err := r.sendRequest(); err == nil {
481 return nil 500 return nil
482 } else if !shouldRetryCancel(r.Error) { 501 } else if !shouldRetryError(r.Error) {
483 return err 502 return err
484 } else { 503 } else {
485 r.Handlers.Retry.Run(r) 504 r.Handlers.Retry.Run(r)
@@ -489,13 +508,16 @@ func (r *Request) Send() error {
489 return r.Error 508 return r.Error
490 } 509 }
491 510
492 r.prepareRetry() 511 if err := r.prepareRetry(); err != nil {
512 r.Error = err
513 return err
514 }
493 continue 515 continue
494 } 516 }
495 } 517 }
496} 518}
497 519
498func (r *Request) prepareRetry() { 520func (r *Request) prepareRetry() error {
499 if r.Config.LogLevel.Matches(aws.LogDebugWithRequestRetries) { 521 if r.Config.LogLevel.Matches(aws.LogDebugWithRequestRetries) {
500 r.Config.Logger.Log(fmt.Sprintf("DEBUG: Retrying Request %s/%s, attempt %d", 522 r.Config.Logger.Log(fmt.Sprintf("DEBUG: Retrying Request %s/%s, attempt %d",
501 r.ClientInfo.ServiceName, r.Operation.Name, r.RetryCount)) 523 r.ClientInfo.ServiceName, r.Operation.Name, r.RetryCount))
@@ -506,12 +528,19 @@ func (r *Request) prepareRetry() {
506 // the request's body even though the Client's Do returned. 528 // the request's body even though the Client's Do returned.
507 r.HTTPRequest = copyHTTPRequest(r.HTTPRequest, nil) 529 r.HTTPRequest = copyHTTPRequest(r.HTTPRequest, nil)
508 r.ResetBody() 530 r.ResetBody()
531 if err := r.Error; err != nil {
532 return awserr.New(ErrCodeSerialization,
533 "failed to prepare body for retry", err)
534
535 }
509 536
510 // Closing response body to ensure that no response body is leaked 537 // Closing response body to ensure that no response body is leaked
511 // between retry attempts. 538 // between retry attempts.
512 if r.HTTPResponse != nil && r.HTTPResponse.Body != nil { 539 if r.HTTPResponse != nil && r.HTTPResponse.Body != nil {
513 r.HTTPResponse.Body.Close() 540 r.HTTPResponse.Body.Close()
514 } 541 }
542
543 return nil
515} 544}
516 545
517func (r *Request) sendRequest() (sendErr error) { 546func (r *Request) sendRequest() (sendErr error) {
@@ -520,7 +549,9 @@ func (r *Request) sendRequest() (sendErr error) {
520 r.Retryable = nil 549 r.Retryable = nil
521 r.Handlers.Send.Run(r) 550 r.Handlers.Send.Run(r)
522 if r.Error != nil { 551 if r.Error != nil {
523 debugLogReqError(r, "Send Request", r.WillRetry(), r.Error) 552 debugLogReqError(r, "Send Request",
553 fmtAttemptCount(r.RetryCount, r.MaxRetries()),
554 r.Error)
524 return r.Error 555 return r.Error
525 } 556 }
526 557
@@ -528,13 +559,17 @@ func (r *Request) sendRequest() (sendErr error) {
528 r.Handlers.ValidateResponse.Run(r) 559 r.Handlers.ValidateResponse.Run(r)
529 if r.Error != nil { 560 if r.Error != nil {
530 r.Handlers.UnmarshalError.Run(r) 561 r.Handlers.UnmarshalError.Run(r)
531 debugLogReqError(r, "Validate Response", r.WillRetry(), r.Error) 562 debugLogReqError(r, "Validate Response",
563 fmtAttemptCount(r.RetryCount, r.MaxRetries()),
564 r.Error)
532 return r.Error 565 return r.Error
533 } 566 }
534 567
535 r.Handlers.Unmarshal.Run(r) 568 r.Handlers.Unmarshal.Run(r)
536 if r.Error != nil { 569 if r.Error != nil {
537 debugLogReqError(r, "Unmarshal Response", r.WillRetry(), r.Error) 570 debugLogReqError(r, "Unmarshal Response",
571 fmtAttemptCount(r.RetryCount, r.MaxRetries()),
572 r.Error)
538 return r.Error 573 return r.Error
539 } 574 }
540 575
@@ -565,13 +600,13 @@ type temporary interface {
565 Temporary() bool 600 Temporary() bool
566} 601}
567 602
568func shouldRetryCancel(err error) bool { 603func shouldRetryError(origErr error) bool {
569 switch err := err.(type) { 604 switch err := origErr.(type) {
570 case awserr.Error: 605 case awserr.Error:
571 if err.Code() == CanceledErrorCode { 606 if err.Code() == CanceledErrorCode {
572 return false 607 return false
573 } 608 }
574 return shouldRetryCancel(err.OrigErr()) 609 return shouldRetryError(err.OrigErr())
575 case *url.Error: 610 case *url.Error:
576 if strings.Contains(err.Error(), "connection refused") { 611 if strings.Contains(err.Error(), "connection refused") {
577 // Refused connections should be retried as the service may not yet 612 // Refused connections should be retried as the service may not yet
@@ -581,14 +616,17 @@ func shouldRetryCancel(err error) bool {
581 } 616 }
582 // *url.Error only implements Temporary after golang 1.6 but since 617 // *url.Error only implements Temporary after golang 1.6 but since
583 // url.Error only wraps the error: 618 // url.Error only wraps the error:
584 return shouldRetryCancel(err.Err) 619 return shouldRetryError(err.Err)
585 case temporary: 620 case temporary:
621 if netErr, ok := err.(*net.OpError); ok && netErr.Op == "dial" {
622 return true
623 }
586 // If the error is temporary, we want to allow continuation of the 624 // If the error is temporary, we want to allow continuation of the
587 // retry process 625 // retry process
588 return err.Temporary() 626 return err.Temporary() || isErrConnectionReset(origErr)
589 case nil: 627 case nil:
590 // `awserr.Error.OrigErr()` can be nil, meaning there was an error but 628 // `awserr.Error.OrigErr()` can be nil, meaning there was an error but
591 // because we don't know the cause, it is marked as retriable. See 629 // because we don't know the cause, it is marked as retryable. See
592 // TestRequest4xxUnretryable for an example. 630 // TestRequest4xxUnretryable for an example.
593 return true 631 return true
594 default: 632 default: