Skip to content

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

@antonsviridov-src

Description

@antonsviridov-src

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions