[1.4] Stream MAVLink log removal and stop asking lsof file by file - #4123
Open
joaoantoniocardoso wants to merge 4 commits into
Open
[1.4] Stream MAVLink log removal and stop asking lsof file by file#4123joaoantoniocardoso wants to merge 4 commits into
joaoantoniocardoso wants to merge 4 commits into
Conversation
joaoantoniocardoso
force-pushed
the
fix/1.4-mavlink-log-remove-stream
branch
4 times, most recently
from
August 11, 2026 20:00
b177421 to
bd26bbc
Compare
… pass Deletion asked lsof whether each file was open, and every lsof call rescans every process in the system, so removing a folder cost a process spawn per file: on a Raspberry Pi 4, 300 MAVLink logs took 42s against 0.2s for a single recursive call. Take one snapshot per deletion and reuse it while recursing, falling back to per-file checks when lsof fails. Searching a folder makes lsof exit with 1 whether or not it found open files, so failure is detected from stderr, with -w silencing the warnings about file systems it cannot stat.
The next commit needs the same streaming response for MAVLink logs.
Removing MAVLink logs only answered once the whole folder was gone, which the frontend gave up on. Stream each deletion like remove_log_stream already does.
…stream Clearing around 1GB of MAVLink logs took longer than the 20s timeout, failing with no feedback while deletion kept going on the vehicle. Stream it into the progress UI the service logs already use.
joaoantoniocardoso
force-pushed
the
fix/1.4-mavlink-log-remove-stream
branch
from
August 11, 2026 20:01
bd26bbc to
0e2cf44
Compare
joaoantoniocardoso
marked this pull request as ready for review
August 11, 2026 20:26
Automated PR Review0. Summary
Backports the streaming MAVLink log deletion to 1.4-dev and, more importantly, folds the per-file 5. UI / UX
6. Code Quality & Style
8. Documentation
Generated by PR Review Bot. This is advisory, a human reviewer must still approve. |
This was referenced Aug 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4105 for 1.4
After:
improved_file_deletion.mp4
Problem
Clearing ~1GB of MAVLink logs failed with
Error: timeout of 20000ms exceededand no progress feedback, while the deletion kept running on the vehicle. System logs already stream their deletion (#3250, backported in #3806), but the MAVLink path was never migrated.Digging into why deletion is slow at all turned up a second, larger problem. Every file is passed to its own
lsofcall to check whether something still has it open, and eachlsofinvocation rescans every process in the system. Deletion therefore costs one process spawn per file and scales with file count, not with bytes removed.Measured on a Raspberry Pi 4 with 300 files (900 MiB), one file deliberately held open:
lsofper file (before)lsofcall with all pathslsof -w +Don the folderunlink()callsAt 3000 files the single
+Dcall still takes 0.245 s, where per-file would take about seven minutes. This is also why/var/logs/blueos(123 files) sat right at the 20 s limit in #3179.Changes
commonwealth.utils.general: take onelsof -w -n -P -S 2 -F n +D <folder>snapshot of open files per deletion and reuse it while recursing, in bothdelete_everythinganddelete_everything_stream. Whenlsoffails the snapshot isNoneand each file falls back to the previous individual check, so the "when in doubt, keep the file" behaviour is unchanged.commander: add/services/remove_mavlink_log_stream, mirroringremove_log_stream. The old endpoint stays for API compatibility.SettingsMenu: consume the stream with no timeout and show the existing progress UI, which now sits next to the MAVLink logs rather than under the service logs.Two details worth flagging for review: searching a folder makes
lsofexit with1whether or not it found open files, so the result is parsed from stdout and failure is detected from stderr; and-wsilences warnings about file systemslsofcannot stat, which are emitted on any Docker host and would otherwise look like failures.Testing
New tests in
commonwealth/utils/tests/test_general.pycover open files surviving deletion, exactly one process being spawned for a 20-file tree (sync and streaming), the fallback path whenlsofis unavailable, andopen_files_underitself.On hardware (Raspberry Pi 4, 1.4 image), 973 MB across 302 MAVLink log files:
lsofpass: 0.74 s, 300 progress updatesCommander stayed responsive throughout: latency for concurrent requests during deletion went from 201 ms median (495 ms worst) to 15 ms. A file held open by another process, standing in for the log ArduPilot is actively writing, was preserved and never reported as deleted. The UI was exercised end to end against a vehicle: progress renders under MAVLink Logs, the folder size drops, and no error is raised.
Notes
Targets
1.4-dev. The equivalent change formasteris ready and will follow as a separate PR.