Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use separate locks for LocalEvaluationClient start() and stop() #39

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading