Skip to content

Commit

Permalink
fix: Use separate locks for LocalEvaluationClient start() and stop() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tyiuhc authored Dec 13, 2024
1 parent fc2ab18 commit f007497
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/main/kotlin/deployment/DeploymentRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ internal class DeploymentRunner(
private val cohortStorage: CohortStorage?,
private val metrics: LocalEvaluationMetrics = LocalEvaluationMetricsWrapper()
) {
private val lock = Once()
private val startLock = Once()
private val stopLock = Once()
private val poller = Executors.newScheduledThreadPool(1, daemonFactory)
private val cohortLoader = if (cohortApi != null && cohortStorage != null) {
CohortLoader(cohortApi, cohortStorage, metrics)
Expand Down Expand Up @@ -71,7 +72,7 @@ internal class DeploymentRunner(
else
amplitudeFlagConfigUpdater

fun start() = lock.once {
fun start() = startLock.once {
flagConfigUpdater.start()
if (cohortLoader != null) {
poller.scheduleWithFixedDelay(
Expand All @@ -97,7 +98,8 @@ internal class DeploymentRunner(
}

fun stop() {
lock.once {
if (!startLock.done) return
stopLock.once {
poller.shutdown()
flagConfigUpdater.shutdown()
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/util/Once.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.amplitude.experiment.util

class Once {
private var done = false
var done = false
fun once(block: () -> Unit) {
synchronized(this) {
if (done) return@once
Expand Down

0 comments on commit f007497

Please sign in to comment.