Skip to content

Commit f385bb4

Browse files
committed
fix(engine): don't start duplicate stacks
1 parent df8c926 commit f385bb4

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

nebula-dsl/src/main/kotlin/com/orbitalhq/nebula/StackRunner.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class StackRunner(private val config: NebulaConfig = NebulaConfig()) {
1919
private val _stackState = ConcurrentHashMap<StackName, Map<String, ComponentInfo<*>>>()
2020

2121
fun submit(submittedStack: NebulaStackWithSource, name: StackName = submittedStack.name, startAsync: Boolean = false): Flux<StackStateEvent> {
22-
val stack = this.stacks.compute(name) { key, existingSpec ->
22+
val storedStack = this.stacks.compute(name) { key, existingSpec ->
2323
if (existingSpec != null) {
2424
if (existingSpec.source == submittedStack.source) {
2525
logger.info { "Received duplicate submission for spec $key - reusing existing stack" }
@@ -31,15 +31,23 @@ class StackRunner(private val config: NebulaConfig = NebulaConfig()) {
3131
}
3232
submittedStack
3333
} ?: error("After submitting stack $name, no stack was created.")
34-
if (startAsync) {
35-
thread {
34+
35+
// Only start if the stack that got stored was the one that got submitted.
36+
// Otherwise it's someone elses stack, and already running
37+
if (submittedStack == storedStack) {
38+
if (startAsync) {
39+
thread {
40+
start(name)
41+
}
42+
} else {
3643
start(name)
3744
}
3845
} else {
39-
start(name)
46+
logger.info { "Not starting stack ${storedStack.name} as stack is already running" }
4047
}
4148

4249

50+
4351
return stackEvents(name)
4452
}
4553

0 commit comments

Comments
 (0)