[1.4] core: services: ardupilot_manager: Prevent i2c file descriptor leak (backport #3878) - #4125
Merged
patrickelectric merged 1 commit intoAug 11, 2026
Conversation
Fix a file descriptor leak in check_for_i2c_device.
SMBus instances were opened without being closed, causing file
descriptors to accumulate over time. In long-running scenarios,
this could reach the system ulimit and trigger:
OSError: [Errno 24] Too many open files
As a result, flight controller boards may fail to be detected
or become inaccessible.
### Changes
- Use context manager (`with SMBus(...) as bus`) to ensure proper cleanup
### Impact
- Prevents FD exhaustion
- Improves reliability of board detection
(cherry picked from commit e6c97dc)
joaoantoniocardoso
marked this pull request as draft
August 11, 2026 20:07
Automated PR Review0. Summary
Straight backport of #3878 to No further comments, nice job 👍 Generated by PR Review Bot. This is advisory, a human reviewer must still approve. |
joaoantoniocardoso
marked this pull request as ready for review
August 11, 2026 20:19
patrickelectric
approved these changes
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.
While working on #4121, I found the same problem already fixed on master.
Backport of #3878 (
e6c97dc4a) to1.4-dev.check_for_i2c_deviceopens anSMBusand never closes it. Every failed probe leaks one/dev/i2c-*file descriptor, so on a vehicle whose Navigator is missing or unresponsive,ardupilot-managerwalks the whole detector list on everyavailable_boardscall and steadily burns through the 1024 FD soft limit.Reproduced on hardware
Raspberry Pi 4 with the Navigator removed, running current
1.4-dev:available_boardsreturns SITL only./dev/i2c-1.OSError: [Errno 24] Too many open filesonsocket.accept();GET /v1.0/boardand/v1.0/available_boardsstop responding entirely.A Raspberry Pi 5 with its Navigator attached, same image, stays flat at 15 FDs total (5 i2c) and under 1 MB of logs, which matches the leak being on the
OSErrorpath.Change
Use the context manager so the bus is closed on both the success and failure paths:
Test plan
1.4-devavailable_boardsrequests driving ~1770 detection sweeps left the FD count flat at 8 with zero open/dev/i2c-*handles, noErrno 24, API still answering 200, and the log file at 1.2 MB after several minutes