Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes context leak in requestOptions #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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