Skip to content

Comments

fix: Concurrency issue in build plugin docker integration#2382

Merged
johanandren merged 2 commits intomainfrom
wip-docker-compose-concurrency-bug
Nov 13, 2025
Merged

fix: Concurrency issue in build plugin docker integration#2382
johanandren merged 2 commits intomainfrom
wip-docker-compose-concurrency-bug

Conversation

@johanandren
Copy link
Contributor

Saw this fail a couple of times yesterday in CI for #2365

Comment on lines 44 to 56
val collectedLines = Vector.newBuilder[String]
val processLogger = ProcessLogger(out =>
collectedLines.synchronized {
collectedLines += out
})
val exitCode = Process(s"docker compose -f $file config", None).!(processLogger)
val lines = collectedLines.synchronized {
collectedLines.result()
}
if (exitCode != 0) {
println("Docker compose call returned non-zero exit code. Command output: + " + lines.mkString("\n"))
}
lines
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use a StringBuffer instead?
It's thread-safe and will make the code much more straightforward.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see now that we don't return a String, but a Seq[String]. That's probably the reason why we didn't use StringBuffer at first place.

Anyway, we can also collect the string and then make a Seq of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we have a different solution in the sbt build itself:

  def commandOutputOrElse(command: String)(default: => String): String = {
    val buffer = new StringBuffer
    val io = new ProcessIO(BasicIO.input(connect = false), BasicIO.processFully(buffer), BasicIO.processFully(buffer))
    if (Process(command).run(io).exitValue() == 0) buffer.toString.trim else default
  }

Something like that would be fine. Or this as is. I don't think the four added lines makes this that hard to follow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The +3 for actually looking at the process return is unrelated boycouting btw

Copy link
Member

@octonato octonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but still think StringBuffer is better.

It's not that it's hard to follow. It's just that StringBuffer is simpler and delivers the same.

Anyway, no strong opinions on this. Feel free to merge as is.

@johanandren johanandren merged commit 2ce7e90 into main Nov 13, 2025
56 checks passed
@johanandren johanandren deleted the wip-docker-compose-concurrency-bug branch November 13, 2025 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants