Skip to content

Commit

Permalink
GRPC Websocket retry more aggresively (#362)
Browse files Browse the repository at this point in the history
We don't want pod to be outofsync
Test passed
  • Loading branch information
xinlili-statsig authored Sep 17, 2024
1 parent 33d7d58 commit 896d795
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/com/statsig/sdk/StatsigUser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ data class StatsigUser private constructor(
var privateAttributes: Map<String, Any>? = null,

@SerializedName("statsigEnvironment")
internal var statsigEnvironment: Map<String, String>? = null
internal var statsigEnvironment: Map<String, String>? = null,
) {
constructor(userID: String) : this(userID = userID, null)

Expand All @@ -73,7 +73,7 @@ data class StatsigUser private constructor(
locale = this.locale,
appVersion = this.appVersion,
custom = this.custom,
statsigEnvironment = this.statsigEnvironment
statsigEnvironment = this.statsigEnvironment,
// DO NOT copy privateAttributes to the logging copy!
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import grpc.generated.statsig_forward_proxy.StatsigForwardProxyOuterClass.Config
import grpc.generated.statsig_forward_proxy.StatsigForwardProxyOuterClass.ConfigSpecResponse
import io.grpc.Channel
import io.grpc.ManagedChannelBuilder
import io.grpc.Status
import io.grpc.StatusException
import io.grpc.stub.StreamObserver
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.BufferOverflow
Expand All @@ -21,11 +19,6 @@ private const val INITIAL_RETRY_BACKOFF_MS: Long = 10 * 1000
private const val RETRY_BACKOFF_MULTIPLIER = 5
private const val FAILOVER_THRESHOLD = 4

private val badRetryCodes: Set<Status.Code> = setOf(
Status.Code.PERMISSION_DENIED,
Status.Code.UNAUTHENTICATED,
)

internal class GRPCWebsocketWorker(
private val sdkKey: String,
private val options: StatsigOptions,
Expand Down Expand Up @@ -128,7 +121,7 @@ internal class GRPCWebsocketWorker(
}

private fun processStreamErrorOrClose(throwable: Throwable? = null) {
shouldRetry = !(throwable is StatusException && throwable.status.code in badRetryCodes) && remainingRetries > 0
shouldRetry = remainingRetries > 0
if ((retryLimit - remainingRetries) == failoverThreshold) {
streamingFallback?.startBackup(dcsFlowBacker)
}
Expand Down

0 comments on commit 896d795

Please sign in to comment.