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

Adds new NewClientWithAddressContextNoEnvTimeout func #437

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 13 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,24 +253,31 @@ func NewClientWithAddress(address string) (client Client, err error) {
// NewClientWithAddressContext instantiates Dapr using specific address (including port).
// Uses the provided context to create the connection.
func NewClientWithAddressContext(ctx context.Context, address string) (client Client, err error) {
if address == "" {
return nil, errors.New("empty address")
}
logger.Printf("dapr client initializing for: %s", address)

timeoutSeconds, err := getClientTimeoutSeconds()
if err != nil {
return nil, err
}
ctx, cancel := context.WithTimeout(ctx, time.Duration(timeoutSeconds)*time.Second)
defer cancel()
return NewClientWithAddressContextNoTimeout(ctx, address)
}

// NewClientWithAddressContextNoTimeout instantiates Dapr using specific address (including port).
// Ignores the DAPR_GRPC_TIMEOUT_SECONDS environment variable and has no
// default timeout.
func NewClientWithAddressContextNoTimeout(ctx context.Context, address string) (client Client, err error) {
if address == "" {
return nil, errors.New("empty address")
}
logger.Printf("dapr client initializing for: %s", address)

conn, err := grpc.DialContext(
ctx,
address,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithUserAgent(userAgent()),
grpc.WithBlock(),
)
cancel()
if err != nil {
return nil, fmt.Errorf("error creating connection to '%s': %w", address, err)
}
Expand Down
Loading