diff --git a/internal/cloud/service.go b/internal/cloud/service.go index f4fe4d4731b..5cad0f8a06c 100644 --- a/internal/cloud/service.go +++ b/internal/cloud/service.go @@ -5,6 +5,7 @@ package cloud import ( "context" "errors" + "os" "sync" "time" @@ -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) @@ -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 @@ -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