From 8222d44c55ceb1b7166149b52bcd1f6a6956ada9 Mon Sep 17 00:00:00 2001 From: Benjamin Rewis <32186188+benjirewis@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:12:56 -0500 Subject: [PATCH] Further bump timeouts when behind SOCKS proxy (#4725) --- config/reader.go | 2 +- internal/cloud/service.go | 26 ++++++++++++++++++++++---- logging/net_appender.go | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/config/reader.go b/config/reader.go index 629df091a5e..1898e41bd6d 100644 --- a/config/reader.go +++ b/config/reader.go @@ -35,7 +35,7 @@ var ( const ( initialReadTimeout = 1 * time.Second readTimeout = 5 * time.Second - readTimeoutBehindProxy = 15 * time.Second + readTimeoutBehindProxy = time.Minute // PackagesDirName is where packages go underneath viamDotDir. PackagesDirName = "packages" // LocalPackagesSuffix is used by the local package manager. 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 diff --git a/logging/net_appender.go b/logging/net_appender.go index b14176f629e..b62179544e3 100644 --- a/logging/net_appender.go +++ b/logging/net_appender.go @@ -24,7 +24,7 @@ var ( writeBatchSize = 100 errUninitializedConnection = errors.New("sharedConn is true and connection is not initialized") logWriteTimeout = 4 * time.Second - logWriteTimeoutBehindProxy = 12 * time.Second + logWriteTimeoutBehindProxy = time.Minute ) // CloudConfig contains the necessary inputs to send logs to the app backend over grpc.