Exception on one interface aborts remaining interfaces and route handling #19

Closed
opened 2026-10-22 17:36:12 -07:00 by eric · 0 comments
Owner

Summary

All the action logic sits in one top-level try { ... } catch (\Throwable $e). If an exception or Error is thrown while handling one interface, the rest of the run is skipped:

  • remaining aliases in $iface_aliases are not handled, and
  • the $remove_backup_route default-route handling for that role never runs.

With the default ['wan'] and no route handling this hardly matters. With e.g. ['wan', 'opt2'], a fault on wan leaves opt2 in the wrong state until the next event or reconcile, and the next run may hit the same fault.

Where

10-wancarp:

  • MASTER loop (around lines 719–748): legacy_interface_flags(), interface_configure()
  • BACKUP loop (around lines 780–802): interface_reset(), interface_configure(), run_cmd()
  • catch block (around lines 871–878): logs, prints END result=exception, exit(1)

Suggested fix

Wrap the per-interface body of each loop in its own try/catch (\Throwable $e). On error: werr("{$ev}: '{$ifkey}' ({$realif}) failed: " . get_class($e) . ': ' . $e->getMessage() . ' @ file:line'), set $failed = true, and continue to the next interface. The route block then still runs, and the END banner reports result=partial. Keep the outer try/catch as the last-resort handler.

Decide whether the MASTER route restore should still run if every interface failed to come up. Restoring OPNsense's route while WAN is down is no worse than the current "route deleted, gateway not ready yet" path, so it's probably fine.

Acceptance

  • With a stub that throws from interface_configure() for the first alias only: the second alias is still handled, route handling runs, END says result=partial.
  • CHANGELOG [Unreleased] entry.
## Summary All the action logic sits in one top-level `try { ... } catch (\Throwable $e)`. If an exception or `Error` is thrown while handling one interface, the rest of the run is skipped: - remaining aliases in `$iface_aliases` are not handled, and - the `$remove_backup_route` default-route handling for that role never runs. With the default `['wan']` and no route handling this hardly matters. With e.g. `['wan', 'opt2']`, a fault on `wan` leaves `opt2` in the wrong state until the next event or reconcile, and the next run may hit the same fault. ## Where `10-wancarp`: - MASTER loop (around lines 719–748): `legacy_interface_flags()`, `interface_configure()` - BACKUP loop (around lines 780–802): `interface_reset()`, `interface_configure()`, `run_cmd()` - catch block (around lines 871–878): logs, prints END `result=exception`, `exit(1)` ## Suggested fix Wrap the per-interface body of each loop in its own `try/catch (\Throwable $e)`. On error: `werr("{$ev}: '{$ifkey}' ({$realif}) failed: " . get_class($e) . ': ' . $e->getMessage() . ' @ file:line')`, set `$failed = true`, and `continue` to the next interface. The route block then still runs, and the END banner reports `result=partial`. Keep the outer try/catch as the last-resort handler. Decide whether the MASTER route restore should still run if every interface failed to come up. Restoring OPNsense's route while WAN is down is no worse than the current "route deleted, gateway not ready yet" path, so it's probably fine. ## Acceptance - With a stub that throws from `interface_configure()` for the first alias only: the second alias is still handled, route handling runs, END says `result=partial`. - CHANGELOG `[Unreleased]` entry.
eric closed this issue 2026-10-23 15:51:23 -07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
eric/10-wancarp#19
No description provided.