Summary
FileUplink::handleEndPacket() (lib/fprime/Svc/FileUplink/FileUplink.cpp:153) logs the FileReceived completion event before calling goToStartMode() (line 160), which is what actually calls this->m_file.osFile.close() (line 196). On our Zephyr FATFS build, Os::File::close() maps directly to fs_close() (lib/fprime-zephyr/fprime-zephyr/Os/File.cpp:85-87), which is what commits the file's directory entry. A consumer that reacts to FileReceived (ground automation, a follow-up FileManager.CalculateCrc/ListDirectory, etc.) can race ahead of the actual filesystem commit and see the file as nonexistent.
Reproduction
On hardware (PROVES V5e, RP2350, Zephyr FATFS), immediately issuing FileManager.CalculateCrc on a path right after its FileUplink.FileReceived event fires intermittently (~15-25% observed rate) returns CalculateCrcFailed ... status 11 (ENOENT-equivalent), even with the correct filename and even after multi-second settle delays in some sessions (ruling out a trivial timing/sync race and suggesting something more structural, e.g. a directory-entry cache not yet flushed). Confirmed independent of filename reuse (fresh, never-before-used filenames reproduce it identically) and independent of which ZephyrUartDriver revision is used (reproducible on both the pre- and post-#457-fix driver, since neither touches this code path) -- confirming this is pre-existing and unrelated to the #457 UART fix.
Suggested fix
Emit FileReceived after goToStartMode()'s close() call completes, not before -- i.e. reorder so the close happens first. This is an upstream nasa/fprime code path (Svc/FileUplink/FileUplink.cpp), so a fix here would need to go upstream eventually, but filing locally first since it manifests concretely on this project's Zephyr FATFS build.
Severity
Moderate -- causes intermittent (not corruption, just "not found yet") failures for any ground automation that acts immediately on FileReceived. Workaround is a short settle delay before the first post-upload file access, but that's a symptom mask, not a fix.
Related to #457 (found during that investigation) but is a separate bug, not fixed by that PR.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WpBURCutAx8281i59nj6fo
Summary
FileUplink::handleEndPacket()(lib/fprime/Svc/FileUplink/FileUplink.cpp:153) logs theFileReceivedcompletion event before callinggoToStartMode()(line 160), which is what actually callsthis->m_file.osFile.close()(line 196). On our Zephyr FATFS build,Os::File::close()maps directly tofs_close()(lib/fprime-zephyr/fprime-zephyr/Os/File.cpp:85-87), which is what commits the file's directory entry. A consumer that reacts toFileReceived(ground automation, a follow-upFileManager.CalculateCrc/ListDirectory, etc.) can race ahead of the actual filesystem commit and see the file as nonexistent.Reproduction
On hardware (PROVES V5e, RP2350, Zephyr FATFS), immediately issuing
FileManager.CalculateCrcon a path right after itsFileUplink.FileReceivedevent fires intermittently (~15-25% observed rate) returnsCalculateCrcFailed ... status 11(ENOENT-equivalent), even with the correct filename and even after multi-second settle delays in some sessions (ruling out a trivial timing/sync race and suggesting something more structural, e.g. a directory-entry cache not yet flushed). Confirmed independent of filename reuse (fresh, never-before-used filenames reproduce it identically) and independent of whichZephyrUartDriverrevision is used (reproducible on both the pre- and post-#457-fix driver, since neither touches this code path) -- confirming this is pre-existing and unrelated to the #457 UART fix.Suggested fix
Emit
FileReceivedaftergoToStartMode()'sclose()call completes, not before -- i.e. reorder so the close happens first. This is an upstreamnasa/fprimecode path (Svc/FileUplink/FileUplink.cpp), so a fix here would need to go upstream eventually, but filing locally first since it manifests concretely on this project's Zephyr FATFS build.Severity
Moderate -- causes intermittent (not corruption, just "not found yet") failures for any ground automation that acts immediately on
FileReceived. Workaround is a short settle delay before the first post-upload file access, but that's a symptom mask, not a fix.Related to #457 (found during that investigation) but is a separate bug, not fixed by that PR.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WpBURCutAx8281i59nj6fo