vert-x3 / issues

Apache License 2.0
37 stars 7 forks source link

FileResolver.unpackFromFileURL #538

Closed yn-tadpole closed 3 years ago

yn-tadpole commented 4 years ago

When file caching is disabled (by set FileSystemOptions.setFileCachingEnabled (false) or -Dvertx.disableFileCaching=true). Every time a static resource is requested, the file will be written to the vertx cache directory, which often causes the file to be occupied and an exception is thrown.

io.vertx.core.VertxException: java.nio.file.FileSystemException: ...(filePath)...: The process cannot access the file because it is being used by another process.

at io.vertx.core.file.impl.FileResolver.unpackFromFileURL(FileResolver.java:240) ~[vertx-core-3.9.2.jar:3.9.2]
at io.vertx.core.file.impl.FileResolver.unpackFromFileURL(FileResolver.java:248) ~[vertx-core-3.9.2.jar:3.9.2]
at io.vertx.core.file.impl.FileResolver.unpackUrlResource(FileResolver.java:212) ~[vertx-core-3.9.2.jar:3.9.2]
at io.vertx.core.file.impl.FileResolver.resolveFile(FileResolver.java:171) ~[vertx-core-3.9.2.jar:3.9.2]
at io.vertx.core.impl.VertxImpl.resolveFile(VertxImpl.java:805) ~[vertx-core-3.9.2.jar:3.9.2]
at io.vertx.core.file.impl.FileSystemImpl$20.perform(FileSystemImpl.java:930) ~[vertx-core-3.9.2.jar:3.9.2]
at io.vertx.core.file.impl.FileSystemImpl$20.perform(FileSystemImpl.java:928) ~[vertx-core-3.9.2.jar:3.9.2]
at io.vertx.core.file.impl.FileSystemImpl$BlockingAction.handle(FileSystemImpl.java:971) ~[vertx-core-3.9.2.jar:3.9.2]
at io.vertx.core.file.impl.FileSystemImpl$BlockingAction.handle(FileSystemImpl.java:951) ~[vertx-core-3.9.2.jar:3.9.2]
at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:313) ~[vertx-core-3.9.2.jar:3.9.2]
at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76) ~[vertx-core-3.9.2.jar:3.9.2]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[?:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[?:1.8.0_201]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [netty-common-4.1.49.Final.jar:4.1.49.Final]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_201]
tsegismont commented 4 years ago

Looks related to https://github.com/eclipse-vertx/vert.x/issues/3510

yn-tadpole commented 4 years ago

It's not a duplicate question. The problem is actually this:

Let's assume that the static folder structure is as follows.

/static/ /static/js/... (20 files) /static/imgs/...(100 files) /static/index.html

When cache is disabled, every request for index.html file will cause all files in js and imgs folders to be re copied to the vertx-cache/... folder. If index.html References to other files in imgs folder will result in a nightmarish cycle.

Please check the following codes: at io.vertx.core.file.impl.FileResolver.unpackFromFileURL(FileResolver.java:240) ~[vertx-core-3.9.2.jar:3.9.2] at io.vertx.core.file.impl.FileResolver.unpackFromFileURL(FileResolver.java:248) ~[vertx-core-3.9.2.jar:3.9.2] at io.vertx.core.file.impl.FileResolver.unpackUrlResource(FileResolver.java:212) ~[vertx-core-3.9.2.jar:3.9.2] at io.vertx.core.file.impl.FileResolver.resolveFile(FileResolver.java:171) ~[vertx-core-3.9.2.jar:3.9.2]

tsegismont commented 4 years ago

Can you please share a small reproducer?

pmlopes commented 4 years ago

@tsegismont and @yn-tadpole, this may look like a very ineffective piece of code, but it is like this by design. Let me explain it a bit further, disable the file cache isn't a feature users do on a live system, usually it is a development feature, where you want to be able to change resources at runtime and the changes are visible without a restart.

So when the the cache is disabled and the /index.html is requested we need to refresh everything under that path because, there is no knowledge on the vert.x side if the goal of the user is to perform a directory listing. If this is the case, the listing would be wrong because we only extracted a single file.

yn-tadpole commented 3 years ago

You are right :)