Skip to content

Commit

Permalink
[Dataapi] GRPC Dial with timeout (#462)
Browse files Browse the repository at this point in the history
Co-authored-by: Siddharth More <Siddhi More>
  • Loading branch information
siddimore authored Apr 10, 2024
1 parent 1a2a591 commit 9a09336
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion disperser/dataapi/grpc_service_availability_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"fmt"
"strings"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -78,6 +79,7 @@ func NewEigenDAServiceHealthCheck(grpcConnection GRPCConn, disperserHostName, ch

// Create Pre-configured connections to the services
// Saves from having to create new connection on each request

disperserConn, err := grpcConnection.Dial(disperserHostName, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{InsecureSkipVerify: true})), grpc.WithBlock())

if err != nil {
Expand All @@ -98,7 +100,12 @@ func NewEigenDAServiceHealthCheck(grpcConnection GRPCConn, disperserHostName, ch

// Create Connection to the service
func (rc *GRPCDialerSkipTLS) Dial(serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
return grpc.Dial(serviceName, opts...)

// TODO: make this a configurable option
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() // Ensure the context is cancelled to free resources

return grpc.DialContext(ctx, serviceName, opts...)
}

// CheckServiceHealth matches the HealthCheckService interface
Expand Down

0 comments on commit 9a09336

Please sign in to comment.