Skip to content

#10220's fix (e17da6f9f9, v5.4.0+) is deeply broken (IDFGH-17926) #18802

Description

@ivmarkov

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

ESP-IDF 5.4.0+

Espressif SoC revision.

All

Operating System used.

Linux

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

None

Development Kit.

Does not matter

Power Supply used.

USB

What is the expected behavior?

#10220's fix (e17da6f, v5.4.0+) put a single-entry readdirstat cache in the per-mount vfs_fat_ctx_t instead of the per-stream vfs_fat_dir_t.

Furthermore, this cache is accessed without fat_ctx->lock and never invalidated by unlink/rename/truncate breaking POSIX readdir cross-stream thread-safety.

This was originally found by @joboet in the Rust STD impl for the ESP-IDF, in issue rust-lang/rust#158727.

The workaround STD did for now is that the ESP-IDF target would stay on readdir_r

Note that this cache would likely be returning wrong stat results even single-threaded when two directories are open at once (?!). So this is not just about "faithfully implementing the readdir multi-threading contract".

Unless I'm missing something, the error is pretty severe.

What is the actual behavior?

See above

Steps to reproduce.

As per above - should be triggered by many cases. The simplest being two directories opened for reading simultaneously.

Debug Logs.


Diagnostic report archive.

No response

More Information.

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions