Last active
March 18, 2026 11:27
-
-
Save zainab-ali/c77b0e96c4c6862e2ec681b2cd60df73 to your computer and use it in GitHub Desktop.
`IOException` on concurrent `createDirectory` calls in Scala Native / cats-effect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //> 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