Skip to content

Commit

Permalink
bump cloud package manager creation timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
benjirewis committed Jan 17, 2025
1 parent fc0e1a2 commit 8211d08
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions internal/cloud/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cloud
import (
"context"
"errors"
"os"
"sync"
"time"

Expand All @@ -16,8 +17,13 @@ import (
"go.viam.com/rdk/resource"
)

// SubtypeName is a constant that identifies the internal cloud connection resource subtype string.
const SubtypeName = "cloud_connection"
const (
// SubtypeName is a constant that identifies the internal cloud connection resource
// subtype string.
SubtypeName = "cloud_connection"
connectTimeout = 5 * time.Second
connectTimeoutBehindProxy = time.Minute
)

// API is the fully qualified API for the internal cloud connection service.
var API = resource.APINamespaceRDKInternal.WithServiceType(SubtypeName)
Expand Down Expand Up @@ -74,7 +80,13 @@ func (cm *cloudManagedService) AcquireConnection(ctx context.Context) (string, r
}

ctx = rpc.ContextWithDialer(ctx, cm.dialer)
timeOutCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
timeout := connectTimeout
// When environment indicates we are behind a proxy, bump timeout. Network
// operations tend to take longer when behind a proxy.
if os.Getenv(rpc.SocksProxyEnvVar) != "" {
timeout = connectTimeoutBehindProxy
}
timeOutCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
conn, err := config.CreateNewGRPCClient(timeOutCtx, &cm.cloudCfg, cm.logger)
return cm.cloudCfg.ID, conn, err
Expand All @@ -93,7 +105,13 @@ func (cm *cloudManagedService) AcquireConnectionAPIKey(ctx context.Context,
}

ctx = rpc.ContextWithDialer(ctx, cm.dialer)
timeOutCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
timeout := connectTimeout
// When environment indicates we are behind a proxy, bump timeout. Network
// operations tend to take longer when behind a proxy.
if os.Getenv(rpc.SocksProxyEnvVar) != "" {
timeout = connectTimeoutBehindProxy
}
timeOutCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
conn, err := config.CreateNewGRPCClientWithAPIKey(timeOutCtx, &cm.cloudCfg, apiKey, apiKeyID, cm.logger)
return cm.cloudCfg.ID, conn, err
Expand Down

0 comments on commit 8211d08

Please sign in to comment.