sbt / io

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

IO.copyFile (and IO.copy): "Channel not open for writing - cannot extend file to required size" #371

Open antonsviridov-src opened 2 weeks ago

antonsviridov-src commented 2 weeks ago

I've been regularly seeing this exception when using IO.copy family of methods.

Here's most recent build: https://github.com/sourcegraph/scip-java/actions/runs/10828494028/job/30043981974?pr=751#step:4:3905

Here's how it's being used: https://github.com/sourcegraph/scip-java/blob/main/build.sbt#L311-L316

When looking at implementation, I'm surprised that it's not delegating to just Files.copy which hopefully should be more battle tested (and seemingly available from Java 7+)

Full stack trace up to the build definition:

Error: 0minfo] #13 90.47 [error] java.io.IOException: Channel not open for writing - cannot extend file to required size
Error: 0minfo] #13 90.47 [error]    at java.base/sun.nio.ch.FileChannelImpl.mapInternal(FileChannelImpl.java:1093)
Error: 0minfo] #13 90.47 [error]    at java.base/sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:1032)
Error: 0minfo] #13 90.47 [error]    at java.base/sun.nio.ch.FileChannelImpl.transferFromFileChannel(FileChannelImpl.java:729)
Error: 0minfo] #13 90.47 [error]    at java.base/sun.nio.ch.FileChannelImpl.transferFrom(FileChannelImpl.java:801)
Error: 0minfo] #13 90.47 [error]    at sbt.io.IO$.loop$1(IO.scala:916)
Error: 0minfo] #13 90.47 [error]    at sbt.io.IO$.$anonfun$copyFile$4(IO.scala:919)
Error: 0minfo] #13 90.47 [error]    at sbt.io.IO$.$anonfun$copyFile$4$adapted(IO.scala:910)
Error: 0minfo] #13 90.47 [error]    at sbt.io.Using.apply(Using.scala:28)
Error: 0minfo] #13 90.47 [error]    at sbt.io.IO$.$anonfun$copyFile$3(IO.scala:910)
Error: 0minfo] #13 90.47 [error]    at sbt.io.IO$.$anonfun$copyFile$3$adapted(IO.scala:909)
Error: 0minfo] #13 90.47 [error]    at sbt.io.Using.apply(Using.scala:28)
Error: 0minfo] #13 90.47 [error]    at sbt.io.IO$.copyFile(IO.scala:909)
Error: 0minfo] #13 90.47 [error]    at sbt.io.IO$.copyImpl(IO.scala:847)
Error: 0minfo] #13 90.47 [error]    at sbt.io.IO$.$anonfun$copy$1(IO.scala:835)
Error: 0minfo] #13 90.47 [error]    at scala.Function$.$anonfun$tupled$1(Function.scala:79)
Error: 0minfo] #13 90.47 [error]    at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:286)
Error: 0minfo] #13 90.47 [error]    at scala.collection.immutable.List.foreach(List.scala:431)
Error: 0minfo] #13 90.47 [error]    at scala.collection.generic.TraversableForwarder.foreach(TraversableForwarder.scala:38)
Error: 0minfo] #13 90.47 [error]    at scala.collection.generic.TraversableForwarder.foreach$(TraversableForwarder.scala:38)
Error: 0minfo] #13 90.47 [error]    at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:47)
Error: 0minfo] #13 90.47 [error]    at scala.collection.TraversableLike.map(TraversableLike.scala:286)
Error: 0minfo] #13 90.47 [error]    at scala.collection.TraversableLike.map$(TraversableLike.scala:279)
Error: 0minfo] #13 90.47 [error]    at scala.collection.AbstractTraversable.map(Traversable.scala:108)
Error: 0minfo] #13 90.47 [error]    at sbt.io.IO$.copy(IO.scala:835)
  1. What's the bug?
  2. Why is the implementation of IO.copyFile so involved? Can we try and use Files.copy instead? I'm happy to submit a PR, but this code hasn't been touched in 10 years so I don't want to do something stupid.
eed3si9n commented 2 weeks ago
  1. What's the bug?

I'm not sure. I don't think I've come across this one. So we're on the same page, we're talking about sbt launching a Docker image, and inside it running another sbt that's saying that it can't copy a file?

Why is the implementation of IO.copyFile so involved?

It's possible that NIO didn't exist when sbt was first implemented or something.

Can we try and use Files.copy instead? I'm happy to submit a PR, but this code hasn't been touched in 10 years so I don't want to do something stupid.

If the copying is happening in your build.sbt, you could try using NIO Files there first and see if the problem persists? Feel free to send a PR for this.