Skip to content

Commit e6c97dc

Browse files
gaojulongpatrickelectric
authored andcommitted
fix(i2c): prevent file descriptor leak in SMBus usage
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
1 parent f069b56 commit e6c97dc

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • core/services/ardupilot_manager/flight_controller_detector/linux

core/services/ardupilot_manager/flight_controller_detector/linux/linux_boards.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def get_serials(self) -> List[Serial]:
2323

2424
def check_for_i2c_device(self, bus_number: int, address: int) -> bool:
2525
try:
26-
bus = SMBus(bus_number)
27-
bus.read_byte_data(address, 0)
26+
with SMBus(bus_number) as bus:
27+
bus.read_byte_data(address, 0)
2828
return True
2929
except OSError:
3030
return False

0 commit comments

Comments
 (0)