Don't serve stale JAR metadata from cache in classpath implementation#6064
Don't serve stale JAR metadata from cache in classpath implementation#6064lrytz merged 1 commit intoscala:2.12.xfrom
Conversation
a966b7d to
7b6a148
Compare
| } | ||
| cache.getOrElseUpdate(zipFile, newClassPathInstance) | ||
| private def createUsingCache(zipFile: AbstractFile, settings: Settings): ClassPath = { | ||
| cache.getOrCreate(zipFile.file.toPath, () => createForZipFile(zipFile)) |
There was a problem hiding this comment.
Removed needlessly noisy logging here.
| private val cache = collection.mutable.Map.empty[java.nio.file.Path, (Stamp, T)] | ||
|
|
||
| def getOrCreate(path: java.nio.file.Path, create: () => T): T = cache.synchronized { | ||
| val lastModified = Files.getLastModifiedTime(path) |
There was a problem hiding this comment.
it seems you can avoid calling getLastModifiedTime here (which calls Files.readAttributesinternally) and use attrs.lastModifiedTime() instead.
There was a problem hiding this comment.
The latest commit also uses attrs.lastModifiedTime()
| def getOrCreate(path: java.nio.file.Path, create: () => T): T = cache.synchronized { | ||
| val lastModified = Files.getLastModifiedTime(path) | ||
| val attrs = Files.readAttributes(path, classOf[BasicFileAttributes]) | ||
| val stamp = Stamp(lastModified, attrs.fileKey()) |
There was a problem hiding this comment.
It seems attrs.fileKey is null on windows, at least on the version i checked. I guess that's fine, lastModified should be enough? Should we check still keep the fileKey check for other platforms?
There was a problem hiding this comment.
Yes, on other platforms we fall back to just the timestamp check. I could declare it as Option[Object] to make it clearer that we've thought about this.
There was a problem hiding this comment.
It's fine without an Option, a commend will do.
Use the last modified timestamp and the file inode to help detect when the file has been overwritten (as is common in SBT builds with `exportJars := true`, or when using snapshot dependencies). Fixes scala/bug#10295
7b6a148 to
bcf47b1
Compare
|
Very nice to have this fixed, thanks! |
|
At some point in the future we can hopefully remove the |
Yep, that would be nice. I can think of two reasons that folks might still want to disable the caching:
So we need to have a better story for resource management here, maybe involving reference counting ("are any instance of Those things aren't straightforward to retrofit onto a |
Original author is @retronym in scala/scala#6064
Original author is @retronym in scala/scala#6064
Adapted from scalac commit bcf47b165ccfd8e1827188f70aeb24e2cecfb80f by Jason Zaugg in scala/scala#6064: Use the last modified timestamp and the file inode to help detect when the file has been overwritten (as is common in SBT builds with `exportJars := true`, or when using snapshot dependencies). Fixes scala/bug#10295
Adapted from scalac commit bcf47b165ccfd8e1827188f70aeb24e2cecfb80f by Jason Zaugg in scala/scala#6064: Use the last modified timestamp and the file inode to help detect when the file has been overwritten (as is common in SBT builds with `exportJars := true`, or when using snapshot dependencies). Fixes scala/bug#10295
Adapted from scalac commit bcf47b165ccfd8e1827188f70aeb24e2cecfb80f by Jason Zaugg in scala/scala#6064: Use the last modified timestamp and the file inode to help detect when the file has been overwritten (as is common in SBT builds with `exportJars := true`, or when using snapshot dependencies). Fixes scala/bug#10295
|
We've hit this bug at Stripe while testing 2.12 with bazel. The incremental compilation didn't work for us. Bazel always puts all class files in a jar before passing them to a dependent target (bazel's name for something like "subproject"). Bazel makes a heavy use of symlinks and I'm wondering if cache invalidation implemented in the PR will handle them properly. I'll see whether I can get a nightly distribution build to work with bazel and verify whether 2.12's HEAD fixes this issue for us. |
|
I just verified with the latest Scala nightly: http://www.scala-lang.org/files/archive/nightly/2.12.x/scala-2.12.4-bin-c1c9c7c.tgz The bug with under compilation in bazel goes away. This is great. |
Use the last modified timestamp and the file inode to help detect
when the file has been overwritten (as is common in SBT builds
with
exportJars := true, or when using snapshot dependencies).Fixes scala/bug#10295
In addition to the enclosed unit test, I manually tested that
the manifestation of this problem reported in sbt/zinc#282
is solved.