Skip to content

Commit

Permalink
cancelling the context cancel function on error in requestOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
katul979 committed Aug 5, 2023
1 parent b128174 commit 7d4a56c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
10 changes: 4 additions & 6 deletions dax/internal/lru/lru_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ package lru
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"reflect"
"sync"
"sync/atomic"
"testing"
"time"

"github.com/aws/aws-sdk-go/aws"
)

func TestLruGet(t *testing.T) {
Expand Down Expand Up @@ -122,11 +123,8 @@ func TestLruEvict(t *testing.T) {

func TestLruTimeout(t *testing.T) {
loadFn := func(ctx aws.Context, key Key) (interface{}, error) {
select {
case <-ctx.Done():
return nil, ctx.Err()
}
return key, nil
<-ctx.Done()
return nil, ctx.Err()
}

c := &Lru{
Expand Down
17 changes: 9 additions & 8 deletions dax/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ func SecureDialContext(endpoint string, skipHostnameVerification bool) (func(ctx
// Only configurations relevent to DAX will be used, others will be ignored.
//
// Example:
// mySession := session.Must(session.NewSession(
// &aws.Config{
// Region: aws.String("us-east-1"),
// Endpoint: aws.String("dax://mycluster.frfx8h.clustercfg.dax.usw2.amazonaws.com:8111"),
// }))
//
// // Create a DAX client from just a session.
// svc := dax.NewWithSession(mySession)
// mySession := session.Must(session.NewSession(
// &aws.Config{
// Region: aws.String("us-east-1"),
// Endpoint: aws.String("dax://mycluster.frfx8h.clustercfg.dax.usw2.amazonaws.com:8111"),
// }))
//
// // Create a DAX client from just a session.
// svc := dax.NewWithSession(mySession)
func NewWithSession(session session.Session) (*Dax, error) {
dc := DefaultConfig()
if session.Config != nil {
Expand Down Expand Up @@ -169,6 +170,7 @@ func (c *Config) requestOptions(read bool, ctx context.Context, opts ...request.
MaxRetries: r,
}
if err := opt.MergeFromRequestOptions(ctx, opts...); err != nil {
defer cfn()
if c.Logger != nil && c.LogLevel.AtLeast(aws.LogDebug) {
c.Logger.Log(fmt.Sprintf("DEBUG: Error in merging from Request Options : %s", err))
}
Expand All @@ -183,7 +185,6 @@ func buildHandlersForUnimplementedOperations() *request.Handlers {
Name: "dax.BuildHandler",
Fn: func(r *request.Request) {
r.Error = errors.New(client.ErrCodeNotImplemented)
return
}})
return h
}
Expand Down

0 comments on commit 7d4a56c

Please sign in to comment.