Skip to content

Commit

Permalink
Further bump timeouts when behind SOCKS proxy (#4725)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjirewis authored Jan 17, 2025
1 parent 923ae38 commit 8222d44
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
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
2 changes: 1 addition & 1 deletion logging/net_appender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8222d44

Please sign in to comment.