sbt / io

IO module for sbt
Apache License 2.0
41 stars 47 forks source link

new IO.delete causing issue #169

Closed eed3si9n closed 6 years ago

eed3si9n commented 6 years ago

steps

On Windows, testOnly testpkg.ServerSpec using IO 1.2.0-M1.

problem

[info]   sbt.internal.io.TranslatedException: Error during a recursive delete of
 path C:\Users\eed3si9n\AppData\Local\Temp\sbt_fcda14cf: Error deleting C:\Users
\eed3si9n\AppData\Local\Temp\sbt_fcda14cf\handshake\project\target\config-classe
s\$dde6a003478912824d62$$anonfun$$nestedInanonfun$root$3$1.class: java.nio.file.
FileSystemException: C:\Users\eed3si9n\AppData\Local\Temp\sbt_fcda14cf\handshake
\project\target\config-classes\$dde6a003478912824d62$$anonfun$$nestedInanonfun$r
oot$3$1.class: The process cannot access the file because it is being used by an
other process.
[info]   at sbt.internal.io.ErrorHandling$.translate(ErrorHandling.scala:12)
[info]   at sbt.io.IO$.delete(IO.scala:488)
[info]   at sbt.io.IO$.withTemporaryDirectory(IO.scala:384)
[info]   at sbt.io.IO$.withTemporaryDirectory(IO.scala:391)
[info]   at testpkg.TestServer$.withTestServer(ServerSpec.scala:46)
[info]   at testpkg.ServerSpec.$anonfun$new$2(ServerSpec.scala:22)
[info]   at org.scalatest.AsyncFreeSpecLike.transformToOutcomeParam$1(AsyncFreeS
pecLike.scala:140)
[info]   at org.scalatest.AsyncFreeSpecLike.$anonfun$registerTestToRun$2(AsyncFr
eeSpecLike.scala:141)
[info]   at org.scalatest.AsyncTestSuite.$anonfun$transformToOutcome$1(AsyncTest
Suite.scala:240)
[info]   at org.scalatest.AsyncFreeSpecLike$$anon$1.apply(AsyncFreeSpecLike.scal
a:408)
[info]   ...
[info]   Cause: sbt.internal.io.TranslatedIOException: Error deleting C:\Users\e
ed3si9n\AppData\Local\Temp\sbt_fcda14cf\handshake\project\target\config-classes\
$dde6a003478912824d62$$anonfun$$nestedInanonfun$root$3$1.class: java.nio.file.Fi
leSystemException: C:\Users\eed3si9n\AppData\Local\Temp\sbt_fcda14cf\handshake\p
roject\target\config-classes\$dde6a003478912824d62$$anonfun$$nestedInanonfun$roo
t$3$1.class: The process cannot access the file because it is being used by anot
her process.
[info]   at sbt.internal.io.ErrorHandling$.translate(ErrorHandling.scala:11)
[info]   at sbt.io.IO$deleter$2$.deletePath(IO.scala:468)
[info]   at sbt.io.IO$deleter$2$.visitFile(IO.scala:476)
[info]   at sbt.io.IO$deleter$2$.visitFile(IO.scala:465)
[info]   at java.nio.file.Files.walkFileTree(Files.java:2670)
[info]   at java.nio.file.Files.walkFileTree(Files.java:2742)
[info]   at sbt.io.IO$.$anonfun$delete$3(IO.scala:489)
[info]   at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:1
2)
[info]   at sbt.internal.io.ErrorHandling$.translate(ErrorHandling.scala:10)
[info]   at sbt.io.IO$.delete(IO.scala:488)
[info]   ...

notes

Using IO 1.1.10 fixes the issue, so something in https://github.com/sbt/io/pull/133 / https://github.com/sbt/io/pull/135 is making IO.delete more sensitive to "The process cannot access the file because it is being used by another process."

We can revert the PR or try something else like https://stackoverflow.com/a/35989142/3827, which also is supposedly is faster than the visitor approach.

/cc @mkeskells, @cunei

mkeskells commented 6 years ago

Lets try the smaller & faster approach - speed was the original target anyway It seems surprising that is changes the behaviour but it will not be the first or last time that I am surprised this week.

eed3si9n commented 6 years ago

I ran into NoSuchFileException with the Files.walk(rootPath), so we still need to hand roll the visitor, but I think I'm going to try a hybrid approach.

eed3si9n commented 6 years ago

https://github.com/sbt/io/pull/170

eed3si9n commented 6 years ago

On Windows on VirtualBox, the original implementation seems to be the fastest:

old delete 1 took 2714.851 ms
delete #135 1 took 3623.421 ms
delete #170 1 took 2850.538 ms
old delete 2 took 2716.804 ms
delete #135 2 took 3732.995 ms
delete #170 2 took 2819.38 ms
old delete 3 took 2747.379 ms
delete #135 3 took 3769.503 ms
delete #170 3 took 2888.485 ms
old delete 4 took 2737.943 ms
delete #135 4 took 3727.32 ms
delete #170 4 took 2889.788 ms
old delete 5 took 2828.599 ms
delete #135 5 took 3677.875 ms
delete #170 5 took 2863.272 ms