Bug 16242 - Unsafe usage of Python subunit module
Summary: Unsafe usage of Python subunit module
Status: NEW
Alias: None
Product: Functional (self) Testing
Classification: QA/Testing
Component: oe-selftest (show other bugs)
Version: 6.0
Hardware: All Multiple
: Medium+ normal
Target Milestone: 6.1 M1
Assignee: Unassigned
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2026-04-10 09:27 UTC by Paul Barker
Modified: 2026-04-16 14:36 UTC (History)
1 user (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: Don't know


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Barker 2026-04-10 09:27:48 UTC
In https://autobuilder.yoctoproject.org/valkyrie/#/builders/97/builds/15 we saw a failure we have seen before, but it it's very rare.

```
2026-04-09 01:18:20,881 - oe-selftest - INFO - testtools.testresult.real._StringException: Traceback (most recent call last):
  File "/srv/pokybuild/yocto-worker/bringup-fast/build/layers/openembedded-core/meta/lib/oeqa/core/utils/concurrencytest.py", line 234, in _run_test
    testserver.run(process_result)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/subunit/__init__.py", line 1219, in run
    protocol.lineReceived(line)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/lib/python3/dist-packages/subunit/__init__.py", line 583, in lineReceived
    self._state.lineReceived(line)
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/lib/python3/dist-packages/subunit/__init__.py", line 422, in lineReceived
    self.details_parser.lineReceived(line)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/lib/python3/dist-packages/subunit/details.py", line 121, in lineReceived
    self._parse_state(line)
    ~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/lib/python3/dist-packages/subunit/details.py", line 104, in _feed_chunks
    residue = self._chunk_parser.write(line)
  File "/usr/lib/python3/dist-packages/subunit/chunked.py", line 138, in write
    return self.state()
           ~~~~~~~~~~^^
  File "/usr/lib/python3/dist-packages/subunit/chunked.py", line 108, in _read_length
    raise ValueError("chunk header invalid: %r" % count_str)
ValueError: chunk header invalid: b'\n'
```
We use the python subunit module (https://github.com/testing-cabal/subunit) to run test cases in subprocesses. Communication of results from child processes back to the parent process uses subunit protocol v1 which is very fragile. It's a text based protocol relying on newlines to separate statements, with buffering involved that can complicate things further. We also multiplex the stdout and stderr streams from test cases over the same pipe back to the parent process. In theory, subunit supports this, but it's a disaster waiting to happen.

What has likely happened here is that a newline has been sent over the pipe by a test case when subunit was expecting a chunk header. This triggers a parsing error in the decoder in chunked.py.

We should move stdout and stderr off the pipe used to communicate test results. We can't discard this "test noise" as it is useful when trying to debug test failures. Instead we should create a separate pipe for this purpose and an additional thread in the parent process to drain this pipe in to the output stream. This requires a bit of work to ensure that the new thread is managed correctly (i.e. drained and shutdown when the parent process finishes). We don't want to rush this and get things wrong, so we will leave this until after the 6.0 release - the issue is very rare so hopefully it won't happen again too soon!