wasm-pack icon indicating copy to clipboard operation
wasm-pack copied to clipboard

wasm-opt might run unnecessarily repetitively on its own output

Open quark-zju opened this issue 2 years ago • 2 comments

🐛 Bug description

On certain filesystems wasm-pack might repetitively call wasm-opt with previous output from wasm-opt as new input of wasm-opt and it's unspecified when the loop ends.

🤔 Expected Behavior

wasm-opt runs exactly once per input file.

👟 Steps to reproduce

This was discovered on EdenFS. But EdenFS can be tricky to build or config externally.

The problem seems obvious, though. In this loop, the directory is being readdir()-ed and written to at the same time. It's unspecified whether the newly written files will appear in the next iteration of readdir() or not. If it does appear, then wasm-opt runs again on its input. I have a fix at https://github.com/quark-zju/wasm-pack/commit/37650afd9dd6bd93b31cda216ee18ae9a5b769d9.

See also https://stackoverflow.com/questions/39015527/is-it-safe-to-rename-files-while-using-readdir

🌍 Your environment

Include the relevant details of your environment. wasm-pack version: 0.10.3 rustc version: 1.65.0

quark-zju avatar Nov 11 '22 06:11 quark-zju

+1 - this happens to me as well on EdenFS. Is there anything we can do to land this?

GuyLewin avatar Aug 08 '23 15:08 GuyLewin

Is this why our Netlify pipeline spends like 15-20 minutes on the wasm-opt step?

dannymcgee avatar Oct 11 '23 22:10 dannymcgee