Skip to content

[Bug]: [Errno 13] Permission denied on temp file during COD reference download (Windows) #32

Description

@JonasWolf303

Email (Optional)

j.wolf95@protonmail.com

Version

1.3.0

Which OS(es) are you using?

  • MacOS
  • Windows
  • Linux

What happened?

On Windows, every reference-structure download during phase search fails with
[Errno 13] Permission denied on a temporary file. The server starts fine and
the web UI works; the failure occurs only when Dara fetches COD entries for the
search, e.g.:

Failed to download 9017498: [Errno 13] Permission denied: 'C:\Users\User1\AppData\Local\Temp\tmpyae69mru'

The same error repeats for other COD IDs, so no reference structures become
available and the search cannot proceed with database-retrieved phases.

To reproduce

  1. Windows 10/11, Python <3.12.x, 64-bit> in a fresh venv
  2. pip install dara-xrd (version <x.y.z>)
  3. dara server
  4. Open http://localhost:8898 and submit any pattern (tested with a
    two-column .xy, Cu radiation, precursor formulas spanning Bi–Fe–O)
  5. Watch the server console during reference retrieval

Expected behavior

Reference CIFs download from COD and the search runs, as on Linux/macOS.

Actual behavior

Every download fails with [Errno 13] Permission denied on a file in the
user temp directory. Full console output:

<paste full traceback / log excerpt here>

What I ruled out

  • Not folder permissions: redirected TMP/TEMP to a user-owned directory
    (C:\xrd\tmp) and restarted the server from the same shell — same error at
    the new location.
  • Added an antivirus exclusion for the temp directory — no change.
  • The machine has normal internet access (pip installs etc. work); the temp
    file is created, so this does not look like a network or ACL problem.

Suspected cause

This looks like the well-known Windows limitation with
tempfile.NamedTemporaryFile(delete=True): on Windows the file cannot be
reopened by name (e.g. by a download/parse step) while the creating handle is
still open, which raises exactly [Errno 13] Permission denied even though
permissions are fine. If the downloader writes to a NamedTemporaryFile and
then reopens it by path, that would reproduce this on every Windows machine
while working normally on Linux/macOS.

Possible fixes: delete=False with explicit cleanup, tempfile.mkstemp +
os.close before reuse, or downloading directly into the Dara cache/server
directory instead of the OS temp dir.

Environment

  • OS: Windows <10/11, version>
  • Python: <3.12.x> (64-bit, venv)
  • dara-xrd: <x.y.z>
  • Install: pip install dara-xrd, default MontyDB backend, default settings
  • BGMN: <bundled / Profex-BGMN bundle x.y on PATH / not yet configured>

Additional context

Workaround for my use case would also be welcome: a way to supply local CIF
files as the reference set through the web UI / REST POST /api/submit, which
would bypass database retrieval entirely for closed chemical systems. If it
already exists, a pointer in the docs would help. Happy to test a patch on
Windows.

Code snippet

Log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions