getzola / zola

A fast static site generator in a single binary with everything built-in. https://www.getzola.org
https://www.getzola.org
MIT License
13.04k stars 920 forks source link

Error: Was not able to copy file ** #1599

Open antcoder opened 2 years ago

antcoder commented 2 years ago

Bug Report

Environment

windows 10 Zola version:0.14.0

Expected Behavior

filename.md add many images_resize short_code:

{% set image = resize_image(path=path, width=width, op=op,format="jpg") %}
<img src="{{ image.url }}" />

filename.md

{{ resize_image(path="/entertainment/filename/1.png", width=728, op="fit_width") }}
{{ resize_image(path="/entertainment/filename/2.png", width=728, op="fit_width") }}
...
{{ resize_image(path="/entertainment/filename/12.png", width=728, op="fit_width") }}
png , image size > 1M

Current Behavior

Failed to build the site Error: Was not able to copy file D:/web/www/temp/site_framework/content/entertainment\filename\2.png to D:\web\www\temp\site_framework\public\entertainment\filename\2.png

Reason:Another program is using this file and the process cannot access it(os error 32)

Step to reproduce

Build site succeed by chance, I guess image is not normal close or async. But zola serve is ok.

Keats commented 2 years ago

Is it always the same image that's failing? Is it used in multiple places?

antcoder commented 2 years ago

Thanks for the reply! Not always the same image failing. image The same image appears in the article content and the article list at the same time. image

error capture image

zzyzxss commented 2 years ago

(Zola 0.14.1 on Windows 10 20H2)

I have yet to have build succeed on Windows with more than one CPU core enabled due to this issue; disabling all but one core (as well as SMT) in the BIOS makes it work every time. Even two cores is too much.

serve works with all cores enabled, but only on the second try. (The first try always fails and if rerun quickly enough the second try always succeeds.)

I am not using image shortcodes. When the error messages show filenames, it's always image copies from content to public that fail, but (as in antcoder's screenshot above) they don't always show filenames. On Zola 0.11.0 (as far back as I can go without errors due to missing features), it always throws the error that doesn't include the filenames.

According to Process Monitor, Zola tries to open the destination file multiple times concurrently, but with ShareMode none, resulting in a sharing violation:

zola-concurrent-file-access

Keats commented 2 years ago

That seems a Windows only issue? Can anyone on Windows try to figure it out?

zzyzxss commented 2 years ago

I'll look at it more when I have the time, but I'm not all that familiar with Rust and it's slow going.

zzyzxss commented 2 years ago

As far as I can tell, the problem is that when there are transparent sections, the pages in those sections get rendered twice (once for the transparent section and once for the opaque ancestor). When I turn all my transparent sections opaque, render_page() gets called the correct number of times and copies the correct number of assets (and the build succeeds). With transparent sections, both those numbers don't quite double, presumably because it crashes first. render_section() always gets called the correct number of times regardless and correctly doesn't copy any assets for my site.

Keats commented 2 years ago

Ah very interesting.

the pages in those sections get rendered twice

that does sounds like a bug

Keats commented 2 years ago

Looks like this happens on Windows CI as well now: https://dev.azure.com/getzola/zola/_build/results?buildId=1722&view=logs&jobId=d2980ad8-b87d-5294-4faf-0af1145b0486&j=d2980ad8-b87d-5294-4faf-0af1145b0486&t=51335d98-55c5-5f23-ce15-2dc0b362ed54