plugins icon indicating copy to clipboard operation
plugins copied to clipboard

os-iperf web gui fails to render when result contains error (eg, due to iperf2 client)

Open cbreezier opened this issue 1 year ago • 1 comments

Important notices Before you add a new report, we ask you kindly to acknowledge the following:

  • [x] I have read the contributing guide lines at https://github.com/opnsense/plugins/blob/master/CONTRIBUTING.md
  • [x] I have searched the existing issues, open and closed, and I'm convinced that mine is new.
  • [x] The title contains the plugin to which this issue belongs

Describe the bug The web UI for iperf can crash and fail to render both open iperf instances and results. A JS TypeError is logged:

Uncaught TypeError: Cannot read properties of undefined (reading 'time')
    at result_to_html (iperf:1278:59)
    at callback (iperf:1317:9)
    at Object.complete (opnsense.js?v=e65c3d146db5fcd1:272:21)
    at c (jquery-3.5.1.min.js?v=e65c3d146db5fcd1:2:28294)
    at Object.fireWith (jquery-3.5.1.min.js?v=e65c3d146db5fcd1:2:29039)
    at l (jquery-3.5.1.min.js?v=e65c3d146db5fcd1:2:79928)
    at XMLHttpRequest.<anonymous> (jquery-3.5.1.min.js?v=e65c3d146db5fcd1:2:82254)

The failing line is output += table_tr_kv("Time", start.timestamp.time);

The JSON payload looks something like:

[
    {
        "start_time": "2024-04-20 14:12:10 +0000",
        "interface": "vtnet0",
        "port": 5830,
        "result": {
            "start": {
                "connected": [],
                "version": "iperf 3.16",
                "system_info": "FreeBSD OPNsense.localdomain 13.2-RELEASE-p11 FreeBSD 13.2-RELEASE-p11 stable\/24.1-n255007-1d6e165fb40 SMP amd64"
            },
            "intervals": [],
            "end": [],
            "error": "error - unable to receive parameters from client: "
        }
    },
    {
        "start_time": "2024-04-20 14:14:54 +0000",
        "interface": "vtnet0",
        "port": 36726
    },
]

The problem is that an errored-out result does contain a start block, but that start block doesn't contain a valid timestamp.

Tip: to validate your setup was working with the previous version, use opnsense-revert (https://docs.opnsense.org/manual/opnsense_tools.html#opnsense-revert)

To Reproduce Steps to reproduce the behavior:

  1. Go to 'http://192.168.1.1/ui/iperf'
  2. Click on 'Create Instance'
  3. An iperf server instance is created and a port is shown
  4. Connect to the specified port using an iperf2 client
  5. An error occurs due to the mismatch in client version (iperf2) and server (iperf3) - I think
  6. Web ui no longer renders iperf instances or results

Expected behavior Even if errors occur, the web ui should not crash and should display errors as best as possible.

Screenshots Not really useful, hard to screenshot something that's just missing in the UI.

Relevant log files See above.

Additional context I believe it's a common mistake to use an iperf2 client. For example, on both Mac and Debian Linux, installing iperf via brew install iperf or apt install iperf installs iperf2. It's not obvious that OPNSense's os-iperf plugin is iperf3, nor that the version incompability causes an irrecoverable crash (in the web ui).

This ticket seems to be very similar: https://github.com/opnsense/plugins/issues/3545 This ticket describes that iperf2 and iperf3 clients can be incompatible: https://github.com/esnet/iperf/issues/530. Regardless, the web ui should display errors better.

Environment Software version used and hardware type if relevant. OPNSense 24.1.6-amd64 os-iperf 1.0_1 iperf 3.16

cbreezier avatar Apr 20 '24 14:04 cbreezier

I've raised a simple PR to fix this: https://github.com/opnsense/plugins/pull/3928

It renders the error instead of trying to render the result.

cbreezier avatar Apr 21 '24 13:04 cbreezier