Skip to content

Instantly share code, notes, and snippets.

@zainab-ali
Last active March 18, 2026 11:27
Show Gist options
  • Select an option

  • Save zainab-ali/c77b0e96c4c6862e2ec681b2cd60df73 to your computer and use it in GitHub Desktop.

Select an option

Save zainab-ali/c77b0e96c4c6862e2ec681b2cd60df73 to your computer and use it in GitHub Desktop.
`IOException` on concurrent `createDirectory` calls in Scala Native / cats-effect
//> using platform native
//> using nativeVersion 0.5.10
//> using dep "org.typelevel::cats-effect::3.7.0"
import java.nio.file.*
import cats.effect.*
/**
When the `foo` doesn't exist, the `createDirectories` calls attempt to create it concurrently.
One of the calls succeeds, but the other results in an `IOException`.
Exception in thread "main" java.io.IOException
at java.nio.file.Files$.createDirectory(Unknown Source)
at java.nio.file.Files$.createDirectories(Unknown Source)
at java.nio.file.Files.createDirectories(Unknown Source)
*/
object CreateDirectoryBug extends IOApp.Simple {
def run: IO[Unit] = {
val createDir = IO(Files.createDirectories(Paths.get("foo")))
(createDir, createDir).parTupled.void
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment