fix-windows-init #74

Merged
narenas merged 4 commits from fix-windows-init into main 2026-05-11 19:10:04 +02:00
Collaborator

Problem

On Windows machines with slow boot times, the agent's network interface
detection could time out (hard limit of 300 seconds) before the network
stack had finished configuring. When that happened the module raised an
exception, was removed from the active module list, and never retried —
leaving the machine unregistered until the service was manually restarted.
The workaround was to configure the Windows service with a delayed start.

The same race condition can also occur on Linux (if systemd starts the
service before DHCP assigns an address) and on macOS (the LaunchDaemon
plist has no network dependency).

Solution

  • onActivation() now returns immediately after reading config and
    creating the REST client, then launches a daemon thread (setup_thread)
    that retries network detection indefinitely until an interface with
    a routable IP is found, then registers with ogcore.
  • On Windows, pythoncom.CoInitialize() is called at thread start so
    that the WMI-based getNetworkInfo() works correctly outside the main
    thread (fixes CO_E_NOTINITIALIZED / -2147221008).
  • Added if self.interface guards in onDeactivation(), onLogin() and
    onLogout() to prevent AttributeError if those events fire before
    the interface is detected.

How to test

  1. Stop the OGAgent service.
  2. Disable the network adapter (Disable-NetAdapter -Name "Ethernet" -Confirm:$false).
  3. Start the service.
  4. Wait ~10 seconds, then re-enable the adapter.
  5. Check the log — you should see the agent retry and eventually register
    with ogcore once the interface appears.
## Problem On Windows machines with slow boot times, the agent's network interface detection could time out (hard limit of 300 seconds) before the network stack had finished configuring. When that happened the module raised an exception, was removed from the active module list, and never retried — leaving the machine unregistered until the service was manually restarted. The workaround was to configure the Windows service with a delayed start. The same race condition can also occur on Linux (if systemd starts the service before DHCP assigns an address) and on macOS (the LaunchDaemon plist has no network dependency). ## Solution - `onActivation()` now returns immediately after reading config and creating the REST client, then launches a daemon thread (`setup_thread`) that retries network detection **indefinitely** until an interface with a routable IP is found, then registers with ogcore. - On Windows, `pythoncom.CoInitialize()` is called at thread start so that the WMI-based `getNetworkInfo()` works correctly outside the main thread (fixes `CO_E_NOTINITIALIZED` / `-2147221008`). - Added `if self.interface` guards in `onDeactivation()`, `onLogin()` and `onLogout()` to prevent `AttributeError` if those events fire before the interface is detected. ## How to test 1. Stop the OGAgent service. 2. Disable the network adapter (`Disable-NetAdapter -Name "Ethernet" -Confirm:$false`). 3. Start the service. 4. Wait ~10 seconds, then re-enable the adapter. 5. Check the log — you should see the agent retry and eventually register with ogcore once the interface appears.
narenas added 4 commits 2026-05-11 19:09:48 +02:00
narenas merged commit eae734458f into main 2026-05-11 19:10:04 +02:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
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: opengnsys/ogagent#74
There is no content yet.