Skip to content

fix: minor correctness and performance bugs#553

Open
TheOfficialDragone wants to merge 1 commit into
Stefal:masterfrom
TheOfficialDragone:fix/minor-bugs
Open

fix: minor correctness and performance bugs#553
TheOfficialDragone wants to merge 1 commit into
Stefal:masterfrom
TheOfficialDragone:fix/minor-bugs

Conversation

@TheOfficialDragone

@TheOfficialDragone TheOfficialDragone commented Jun 28, 2026

Copy link
Copy Markdown

No description provided.

- RTKBaseConfigManager.expand_path(): replace str.strip() with
  str.removeprefix() for $BASEDIR substitution. strip() removes any
  character in the set from both ends, not just the prefix, which can
  silently corrupt paths containing those characters.

- LogManager.updateAvailableLogs(): move sort() call outside the for
  loop. Sorting on every append is O(n² log n); with many log files on
  a Raspberry Pi this is measurably slow.

- network_infos.get_interfaces_infos(): merge two nmcli.device.show()
  calls per interface into one, halving the number of subprocess forks
  when displaying network info in the settings page.

- server.update_settings(): guard against empty json_msg before pop()
  to prevent an uncaught IndexError that would silently kill the socket
  handler under malformed client input.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@TheOfficialDragone

Copy link
Copy Markdown
Author

What this PR fixes

Four correctness and performance bugs found by static code review. None cause crashes, but two produce silently wrong results.


1. RTKBaseConfigManager.expand_path()str.strip() is not prefix removal (RTKBaseConfigManager.py)

# Before (wrong)
datadir.strip("$BASEDIR/")

str.strip(chars) removes any character in the set from both ends of the string — it is not a prefix-removal operation. For a value like "$BASEDIR/data" it works by coincidence, but for any path whose trailing characters overlap with the set ($, B, A, S, E, D, I, R, /) the path is silently truncated.

# After (correct, Python 3.9+ — already the minimum)
datadir.removeprefix("$BASEDIR/")

Same fix applied to logdir.


2. LogManager.updateAvailableLogs()sort() called inside the loop (LogManager.py)

# Before: O(n² log n)
for log in glob(self.log_path + "/*"):
    self.available_logs.append(...)
    self.available_logs.sort(...)   # called on every iteration
# After: O(n log n)
for log in glob(self.log_path + "/*"):
    self.available_logs.append(...)

self.available_logs.sort(...)       # called once after the loop

With hundreds of log files on a Raspberry Pi the difference is measurable.


3. network_infos.get_interfaces_infos()nmcli.device.show() called twice per interface (network_infos.py)

# Before: two subprocess forks per interface
conn_name = get_conn_name(k)                    # calls nmcli.device.show(k) internally
device_info["hwaddr"] = nmcli.device.show(k).get('GENERAL.HWADDR')   # second call
# After: one call, both values extracted from the same result
device_show = nmcli.device.show(k)
conn_name = device_show.get("GENERAL.CONNECTION")
device_info["hwaddr"] = device_show.get("GENERAL.HWADDR")

Also wraps the call in try/except nmcli.NotExistException for consistency with get_conn_name().


4. server.update_settings() — unguarded list.pop() on socket input (server.py)

# Before: IndexError if client sends empty list
source_section = json_msg.pop().get("source_form")
# After: early return on empty/malformed input
if not json_msg:
    print("ERROR: update_settings received empty message")
    return
source_section = json_msg.pop().get("source_form")

Under gevent, an unhandled IndexError inside a socket handler is swallowed silently, leaving the handler dead for the rest of the session.


How to test

  • Set datadir or logdir to a path with characters that overlap the old strip set (e.g. $BASEDIR/rinex_data) and confirm the expanded path is correct
  • Open the Logs page with a large number of log files and confirm the list loads correctly and is sorted
  • Open the Settings page and confirm network interfaces show the correct connection name and MAC address with a single nmcli call
  • Send a malformed form data socket event (empty array) and confirm the server does not crash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant