Skip to content

Stale PAPI connection cache makes one container test failure fail the whole suite #4199

Open

Description

@vvalderrv
PapiSocketExecutor caches a never-connected client; one failed container test cascades into whole-suite failure

## Summary

A failed PAPI connect to a container VPP socket leaves a dead client in `PapiSocketExecutor.conn_cache`. Every later test that uses the same socket key reuses the dead client and fails. One real test failure turns into a whole-suite failure.

Seen in the nightly coverage run
https://github.com/FDio/csit/actions/runs/42780790118
(job `csit-vpp-perf-report-coverage-2610-3nb-spr`, test set `3nb-spr-vpp-cov-srv6-00`).

- 1 real failure: `9000B-1c-avf-ethip6srhip6-ip6base-srv6proxy-masq-ndrpdr`
- 38 cascaded failures: every later test in the `srv6proxy-masq` and `srv6proxy-stat` suites (AVF and non-AVF), all with
  `Failed to execute command in container DUT1_CNF1.`

## Symptom in the cascaded tests

1. Container starts, VPP inside starts. `verify_vppctl()` passes (CLI works).
2. `verify_vpp_papi()` fails all 120 retries.
3. The debug step `cat /tmp/vppd.log` fails (file does not exist in the container) and raises `Failed to execute command in container`, which masks the real error (`VPP PAPI fails in container`).

```text
ContainerUtils.py:154 start_vpp_in_all_containers
ContainerUtils.py:192 verify_vpp_in_all_containers
ContainerUtils.py:742 verify_vpp_papi  -> self.execute("cat /tmp/vppd.log")
ContainerUtils.py:1229 execute -> RuntimeError: Failed to execute command in container DUT1_CNF1.
```

## Root cause

### 1. `PapiSocketExecutor.__enter__` caches before connecting

`resources/libraries/python/PapiExecutor.py`, `__enter__()`:

```python
vpp_instance = self.ensure_vpp_instance()
# Store into cache as soon as possible.
# If connection fails, it is better to attempt disconnect anyway.
self.set_connected_client(vpp_instance)
...
vpp_instance.connect("csit_socket", do_async=True)   # raises here
```

If `connect()` raises (here `ConnectionResetError`), the never-connected client stays in `conn_cache` under key `(host, port, socket_path)`. Nothing removes it.

### 2. The next user gets the dead client

Same method, top:

```python
vpp_instance = self.get_connected_client(check_connected=False)
if vpp_instance is not None:
    return self          # dead client reused
```

`_execute_sync()` then hits `IOError` (`BrokenPipeError`) and converts it to `AssertionError`. `verify_vpp_papi()` catches `(RuntimeError, AssertionError)`, sleeps, and retries 120 times against the same dead client.

### 3. Teardown order re-poisons the cache every time

`resources/libraries/robot/shared/test_teardown.robot`, `Tear down test`, with actions `srv6 | container | performance` (as set in the srv6proxy test files):

1. `container` -> `destroy_all_containers()` -> `_disconnect_papi_to_all_containers()` (clears the key) -> containers destroyed.
2. `performance` (runs only when the test failed) -> `Send traffic at specified rate` -> `VPP Enable Traces On All DUTs` -> `run_cli_cmd_on_all_sockets()` -> iterates **all** PAPI sockets still in the topology, including `/tmp/vpp_sockets/DUT1_CNF1/api.sock` whose container is already gone -> connect fails -> dead client cached (see 1).
3. `Clean Sockets On All Nodes` only does `node.pop("sockets")` (`topology.py:1160`). It does not disconnect. Its comment assumes "Containers are disconnected and destroyed already", which is no longer true after step 2.

Every cascaded test also fails, so its teardown repeats steps 1-2 and re-poisons the cache. The loop is self-sustaining until the suite ends.

Evidence from the first failing test's teardown:

```text
Also teardown failed:
1) ConnectionResetError: [Errno 104] Connection reset by peer
   (traceback: VPPUtil.vpp_enable_traces_on_all_duts -> run_cli_cmd_on_all_sockets
    -> run_cli_cmd -> PapiSocketExecutor.__enter__ -> vpp_instance.connect)
2) Failed to run 'cli_inband show trace max 100' PAPI command on host 10.30.51.54
3) Failed to run 'cli_inband show memory verbose ...' PAPI command on host 10.30.51.54
```

## Suggested fixes

Any one breaks the loop. The first is the real fix.

1. **`PapiExecutor.__enter__`**: if `connect()` raises, call `disconnect_by_key(key)` (or `del conn_cache[key]`) before re-raising. Never leave a never-connected client cached.
2. **`test_teardown.robot`**: run the `performance` action before `container`, or make `Clean Sockets On All Nodes` call `disconnect_all_sockets_by_node()` so container socket keys are always dropped.
3. **`run_cli_cmd_on_all_sockets`** (used by `vpp_enable_traces_on_all_duts`, `show_packet_trace_on_all_duts`): skip sockets whose container no longer exists, or honour `fail_on_error=False` per socket.
4. **`ContainerUtils.verify_vpp_papi` / `verify_vppctl`**: wrap `self.execute("cat /tmp/vppd.log")` in try/except so the real `VPP PAPI fails in container` error surfaces instead of being masked.

## Separate issue (the trigger, not the cascade)

`9000B-*-srv6proxy-masq` cannot pass as configured. The memif interface has MTU 9000. End.AM forwards the full SRH-encapsulated packet (~9066B). VPP drops it:

```text
ip6-icmp-error   packet too big response sent
ip6-icmp-error   error message dropped
```

The `dyn` (End.AD) and `stat` (End.AS) variants decapsulate first, so the inner 9000B frame fits. Options: set `Jumbo.MTU_JUMBO` (9145) on memif interfaces in jumbo tests, or drop 9000B from the masq test set. Worth a separate issue.

## How the root cause was found

1. Pulled the job log with `gh run view 42780790118 --repo FDio/csit --log`. 75 PASS, 39 FAIL. All failures were in the `srv6proxy` suites. The first failure was `9000B-1c-avf-...-srv6proxy-masq` with `No lower bound` plus `Also teardown failed: ConnectionResetError`. Every later failure was `Failed to execute command in container DUT1_CNF1`.
2. Compared with four other recent runs of the same job (`l2-00`, `ip6-00`, `ip4tun-01`, `ip4tun-04`). Each run covers a different test set, so "fails every night" is really several distinct failures. Only the srv6 run shows the container cascade.
3. Downloaded `log.html.gz` from https://logs.fd.io/vex-yul-rot-jenkins-1/csit-vpp-perf-report-coverage-2610-3nb-spr/42780790118/. Robot stores messages as base64+zlib strings in the HTML; decoded them with a short Python script to get the full keyword-level log.
4. In the cascaded tests, found that `vppctl show pci` in the container succeeded, `verify_vpp_papi` exhausted 120 retries, and `cat /tmp/vppd.log` returned `No such file or directory`, producing the misleading error.
5. In the trigger test, found TRex `forwarded_count=0` on every trial, and `show node counters` on the DUT showing all packets in `ip6-icmp-error: packet too big`, with memif MTU `9000/0/0/0` versus iavf MTU `9145`.
6. Read `PapiExecutor.py` (`__enter__`, `disconnect_by_key`, `_execute_sync`), `ContainerUtils.py` (`verify_vpp_papi`, `_disconnect_papi_to_all_containers`), `test_teardown.robot` (action order), `performance_actions.robot` (`vpp-enable-packettrace`), and `topology.py` (`clean_sockets_on_all_nodes`). Matched the teardown traceback (`vpp_enable_traces_on_all_duts -> __enter__ -> connect -> ConnectionResetError`) to the cache-before-connect code path.

---

### Review comment (Claude)

Reviewed the analysis above against the CSIT source and the decoded Robot log.

Confirmed:

- `PapiSocketExecutor.__enter__` calls `set_connected_client()` before `connect()`, and there is no cleanup path when `connect()` raises. The in-code comment ("If connection fails, it is better to attempt disconnect anyway") describes an intent that no code implements.
- `__enter__` returns a cached client without checking that it is connected (`check_connected=False`), so a poisoned entry is never re-established.
- The teardown order `container -> performance` means `destroy_all_containers()` clears the container key, then `vpp_enable_traces_on_all_duts()` recreates it in a failed state. `clean_sockets_on_all_nodes()` only removes the topology entries and does not touch `conn_cache`.
- The `ConnectionResetError` in the trigger test's teardown traceback originates in `__enter__ -> vpp_instance.connect`, which is exactly the cache-before-connect path.
- The trigger failure is deterministic: 100% loss on all trials, with `ip6-icmp-error packet too big` counters and memif MTU 9000.

Caveats:

- Robot's `log.html` stores a deduplicated string table, so per-test ordering of cache hits (`Activated cached PAPI client for key: ... DUT1_CNF1`) could not be counted directly. The cache-poisoning mechanism is inferred from the code path plus the observed symptoms (CLI OK, PAPI fails 120x, same key, repeats every test). A quick way to confirm: add a `logger.warn` in `__enter__` when a cached client is returned, and rerun the masq suite.
- Fix 1 (clean up the cache when `connect()` raises) is sufficient on its own and is the safest minimal change. Fixes 2-4 are hardening.
- The `9000B masq` MTU problem is independent and should be tracked separately.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions