Plug: retries for temporary filename often fail on Windows OS

There is a problem with the random filename logic in Plug when run on Windows, because :os.timestamp does not give microsecond resolution - at this point in the code:

Typically:

iex(1)> IO.inspect :os.timestamp; IO.inspect :os.timestamp
{1496, 22882, 547000}
{1496, 22882, 547000}

And as there are only 10 reties, it sometimes results in:

    ** (Plug.UploadError) tried 10 times to create an uploaded file at C:\Windows\TEMP/plug-1495 but failed. Set PLUG_TMPDIR to a directory with write permission                                                                               

See pull request:

Look at Forking a Repo. You have to push the change to your own fork of the repo to do a PR.

Thanks for that, see https://github.com/elixir-lang/plug/pull/560

2 Likes

Thanks for contributing! :heart: