Skip to content

ci: add native freeBSD ci job - #36147

Open
willcl-ark wants to merge 5 commits into
bitcoin:masterfrom
willcl-ark:bsd-ci
Open

willcl-ark wants to merge 5 commits into
bitcoin:masterfrom
willcl-ark:bsd-ci

Conversation

@willcl-ark

@willcl-ark willcl-ark commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

This replaces the FreeBSD cross-compilation job with a native build and test job inside a FreeBSD VM. NetBSD and OpenBSD retain their existing cross-compilation jobs.

We currently cross-compile BSD binaries without testing them in this repository. Running tests before merge should help catch platform-specific regressions that would otherwise first appear in nightly builds. This starts with FreeBSD because it has been the most reliable BSD platform in the nightly jobs.

As we don't have native FreeBSD runners, the job uses vmactions/freebsd-vm, which is also used by the nightly builds. It reuses the existing CI scripts, depends build, and cache actions where possible.

The VM image is cached after its prepare step installs dependencies. The job also restores and saves the usual build caches. Initial testing on free GitHub Actions runners took approximately 60 minutes without caches and 20–30 minutes with caches populated. Performance on Warp runners remains untested.

The VM uses the runner's available CPU count and 75% of its RAM, leaving the remaining memory for the host and VM overhead. There is some overhead after testing while rsync copies cache directories back out of the VM.

The patchset also suppresses lsof warnings on FreeBSD that would otherwise interfere with functional tests.

The job requires enabling one additional action:

vmactions/freebsd-vm@v1

@DrahtBot DrahtBot added the Tests label Sep 2, 2026
@DrahtBot

DrahtBot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Concept ACK pinheadmz, vasild, winterrdog
Approach ACK hebasto

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36872 (ci: Share qa-assets across GitHub Actions jobs by jaromil)
  • #36042 (build: Bump g++ minimum supported version to 13 by maflcko)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@maflcko

maflcko commented Sep 2, 2026

Copy link
Copy Markdown
Member

We currently cross compile various BSD binaries but do not test them. This leads to regressions on master which are noticed in nightly builds and fixed here, recent examples include #36078 and #36145.

Build and test the binaries in this repo as part of our CI instead to avoid this regression/fix flip-flopping.

I think this requires a stronger motivation, to explain that this will actually reduce overall workload.

Those vm-in-a-vm tests are extremely brittle (hebasto/bitcoin-core-nightly#230 (comment), hebasto/bitcoin-core-nightly#81, ... etc)

So if those tasks are added here, we need to understand that this is the "hot path" (for all pull requests) and before this is merged, there needs to be several people who monitor those intermittent failures on those platforms and then categorize them into "intermittent", "unrelated", etc.

If this isn't done, then devs will just ignore all CI results because the false-positive rate is too high and just re-run it until it is green. This may then degrade non-*BSD code at a slight benefit of avoid some trivial test-only BSD fixups.

Maybe I am wrong, but I wanted to raise the point to not miss the large picture here.

@hebasto

hebasto commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

We currently cross compile various BSD binaries but do not test them. This leads to regressions on master which are noticed in nightly builds and fixed here, recent examples include #36078 and #36145.
Build and test the binaries in this repo as part of our CI instead to avoid this regression/fix flip-flopping.

I think this requires a stronger motivation, to explain that this will actually reduce overall workload.

Those vm-in-a-vm tests are extremely brittle (hebasto/bitcoin-core-nightly#230 (comment), hebasto/bitcoin-core-nightly#81, ... etc)

So if those tasks are added here, we need to understand that this is the "hot path" (for all pull requests) and before this is merged, there needs to be several people who monitor those intermittent failures on those platforms and then categorize them into "intermittent", "unrelated", etc.

If this isn't done, then devs will just ignore all CI results because the false-positive rate is too high and just re-run it until it is green. This may then degrade non-*BSD code at a slight benefit of avoid some trivial test-only BSD fixups.

Maybe I am wrong, but I wanted to raise the point to not miss the large picture here.

We might begin with FreeBSD only, which has shown high stability over a long period.

@maflcko

maflcko commented Sep 2, 2026

Copy link
Copy Markdown
Member

We might begin with FreeBSD only, which showed a high stability over a long period.

Your link shows an unrelated failure for the 35th build (second page). Not sure if this is accurate, but if every 35th build fails and Bitcoin Core has 35 pushes per day, then every day there will be one additional unrelated CI failure.

Maybe there can be a one-month trial period and then a summary is presented with all CI failures and each of them annotated with "intermittent" (y/n), "unrelated" (y/n)?

Also, even if a failure is related, it can still be intermittent, so merging this pull request does not guarantee to prevent fixups such as #36145, because the failure happens intermittently.

@willcl-ark

Copy link
Copy Markdown
Member Author

I did not understand these VMs to be flaky. I didn't observe any flakiness in testing, but probably only ran about 15 runs (x3 jobs), so perhaps I'm due a random flake-failure soon 😋

The actions are used by a few other high-profile projects like tokio and sccache as well as:

  • tukaani-project/xz using OpenBSD (workflow)
  • hashcat/hashcat using OpenBSD
  • acmesh-official/acme.sh using OpenBSD
  • aws/aws-lc-rs using FreeBSD (workflow)
  • mozilla/sccache using FreeBSD
  • aristocratos/btop using OpenBSD
  • stalwartlabs/stalwart using FreeBSD
  • deskflow/deskflow using FreeBSD
  • FrameworkComputer/framework-system using FreeBSD

But I'd imagine our functional tests put significantly more strain on the vm than any of those projects are doing.

I asked codex to take a look at the last months-worth of runs on hebasto's nightly repo:

Details

hebasto/bitcoin-core-nightly
from 2026-08-02 through 2026-09-02. Pull-request runs were excluded. The
nightly sample consists of runs with the workflow_run event. Manual
workflow_dispatch failures are listed separately where they add useful
context.

Summary

Workflow Nightly runs Successful Failed Cancelled
FreeBSD 33 33 0 0
NetBSD 33 28 4 1
OpenBSD 33 10 19 4

The logs for all 29 failed runs were downloaded and inspected.

FreeBSD looks stable in this sample. NetBSD has a small number of nightly
failures, mostly caused by platform resource limits or platform-sensitive
tests. OpenBSD has a high failure rate, but most failures are repeatable test
or platform problems rather than failures to boot the VM.

NetBSD

Nightly failures

  • Run 906,
    2026-08-25: feature_block.py timed out waiting for the expected peer
    disconnect. Other jobs showed the NetBSD file-descriptor limit.
  • Run 899,
    2026-08-20: feature_block.py timed out waiting for a peer disconnect after
    the node had rejected the block.
  • Run 892,
    2026-08-14: wallet_listtransactions.py failed when generateblock
    returned bad-txns-inputs-missingorspent.
  • Run 888,
    2026-08-10: wallet_listtransactions.py failed with the same
    TestBlockValidity error.

The feature_block.py failures look like delayed networking or scheduling in
the guest: the node log records the rejection and disconnect, while the test
does not observe the disconnect before its timeout. The wallet failures are
functional test failures and should not be counted as generic VM boot
failures.

Manual failures

The following manual runs on 2026-08-25 failed during test setup because the
guest did not have enough file descriptors:

The common messages were:

Not enough file descriptors available. 256 available, 290 required.
Warning: Reducing -maxconnections ... because of system limitations.

These are reproducible NetBSD configuration or test-environment failures, not
random VM failures.

There was one additional manual failure:

  • Run 895,
    2026-08-16: the VM boot probe timed out and QEMU was restarted. The run also
    contained feature_anchors.py and interface_http.py timing failures.

This is the clearest NetBSD example of actual VM or infrastructure flakiness.

OpenBSD

Repeated interface_gui.py failures

interface_gui.py failed in runs 738,
739,
740,
743,
744,
745,
746,
747,
748,
749,
and 751.

The recurring error was:

GLib-CRITICAL: g_main_context_pop_thread_default:
assertion 'stack != NULL' failed

This is highly repeatable across OpenBSD 7.8 and 7.9 GUI jobs. It looks like
an OpenBSD/Qt shutdown or test-environment problem, not QEMU randomly failing.

Repeated P2P test timeouts

p2p_private_broadcast.py or
p2p_private_broadcast_retry_v1.py failed in runs 738,
754,
757,
758,
761,
765,
766,
772,
and 779.

The test waited exactly 480 seconds for all addresses to advertise
NODE_P2P_V2:

Predicate ... not true after 480.0 seconds

The node remained responsive and answered getnodeaddresses RPC requests, but
the expected service flags never appeared. Because the same test fails in the
same way across many consecutive OpenBSD runs, this looks like an OpenBSD/test
interaction or severe guest-performance problem rather than a generic boot
failure.

Package and VM infrastructure failures

  • Run 754:
    OpenBSD package installation failed with Premature end of archive while
    installing nghttp2.
  • Run 761,
    765,
    and 766:
    package downloads included 404s or connection timeouts.

These failures are package-mirror or network infrastructure failures. They are
separate from the repeated functional test failures.

Conclusion

For this one-month sample:

  • FreeBSD: no observed nightly failures.
  • NetBSD: some real guest or scheduling sensitivity, but most failures are
    resource-limit or functional-test issues. The one clear VM boot failure was
    on 2026-08-16.
  • OpenBSD: 19 failed nightly runs out of 33. The failure count is dominated by
    repeatable interface_gui.py and p2p_private_broadcast* failures, with a
    few package-mirror failures. It would be misleading to attribute all 19 to
    vmactions or QEMU flakiness.

The next useful experiment would be to fix or disable the known OpenBSD GUI
and P2P test incompatibilities, raise the NetBSD file-descriptor limit, and
then repeat the same nightly comparison. That would leave a much cleaner
measurement of VM-level reliability.

I have not observed the interface_gui.py failures that hebasto's repo sees on OpenBSD. I did see a failure on p2p_private_broadcast_retry_v1.py once or twice and did have that test disabled on *BSD in one iteration; if that test in particular is flaky it could be disabled on these jobs.

Most of the other failures at first glance appear to be GHA/package archive 404 or other network infra failures and I wouldn't attribute them to the VMs being flaky, so I'm not 100% convinced that critique is warranted.

That said I don't want to add known-flaky jobs and you are correct to call out they could be more work to maintain than porting over a few fixes, if they are unreliable. I suppose the only unclear bit is at what cost level do we prefer to merge buggy code and fix later, vs run more jobs on every PR and merge to prevent that happening in the first place...

We might begin with FreeBSD only, which has shown high stability over a long period.

Happy to start with FreeBSD only if that's preferable.

@maflcko

maflcko commented Sep 2, 2026

Copy link
Copy Markdown
Member

We might begin with FreeBSD only, which has shown high stability over a long period.

Happy to start with FreeBSD only if that's preferable.

Sure, I am not against this pull request, but then the motivation is off, because the two motivating issues are about netbsd and openbsd, which for some reason have a lot more false positive intermittent failures?

It still seems that the remaining fixups required for FreeBSD are less effort than maintaining the FreeBSD ci task here? (Recall that codex only looked at the last month with daily builds, but it missed the failure from 35 days ago and recall that Bitcoin Core has a higher CI volume than just one build per day, so any rare failure will amplify)

Again, seems fine to merge this, but as long as the false positive rate is higher than the true positive rate, it doesn't seem worth it overall.

@willcl-ark

Copy link
Copy Markdown
Member Author

Scanning the last 90 days (where logs still exist) in hebasto's repo I really only see this one where the vm failed to boot: https://github.com/hebasto/bitcoin-core-nightly/actions/runs/29139756629/job/86510586228#step:2:188

There are a handful of "random" functional test issues, which could be attributable to the vm-in-vm setup, but I'd recommend disabling those few tests. There are a number of legitimate functional test failures repeated over many days (e.g interface_gui.py) and few semi-legitimate-looking errors which could have been vm-flakiness.

Including the ~legit test timeout-type failures, but excluding real test failures by my count I see 18 "flaky failures" out of 812 jobs over the 90 days, which or 2.2%.

as long as the false positive rate is higher than the true positive rate, it doesn't seem worth it overall.

Our CI jobs have between a 7 and 2% fail rate (assuming all current failures are true-positives), per our CI job statistics.

So for references 2.2% as a potential false-positive rate is ~ in the same ballpark as the true-failures we see on jobs today (assuming all are true-failures). I agree a flakiness ~= to the bug-catching ability of non-flaky tests isn't great.

If we are more happy to backport fixes from broken nightly/master builds than run CI jobs here as we are worried they'll be too flaky (which is more like a regular CI/CD process to be honest) then that works for me too.

I'll leave this in draft for a few days in case anyone else wants to weigh in, before closing.

@hebasto

hebasto commented Sep 3, 2026

Copy link
Copy Markdown
Member

Concept ACK on having at least one CI job that runs tests on a *BSD platform.

@maflcko

maflcko commented Sep 17, 2026

Copy link
Copy Markdown
Member

Including the ~legit test timeout-type failures, but excluding real test failures by my count I see 18 "flaky failures" out of 812 jobs over the 90 days, which or 2.2%.

Is this the average over all BSDs? Because I see 5 OpenBSD failures in the last 10 days alone, which is more than 10%.

I guess we could add the FreeBSD one only, but I wonder what issues it would have caught this year. Mostly only #34331?

I'd say we don't care about FreeBSD failures that happen on other platforms as well, so true positive rate is meant as the "marginal" (additional or exclusive) true positive rate.

I guess it could be tried for a month or two, to see what happens in reality.

@maflcko

maflcko commented Nov 12, 2026

Copy link
Copy Markdown
Member

@hebasto

hebasto commented Nov 12, 2026

Copy link
Copy Markdown
Member

@maflcko

maflcko commented Nov 12, 2026

Copy link
Copy Markdown
Member

Sure, logging can't hurt, but I don't think it is possible to fix the OOM or OOS like System.IO.IOException: No space left on device : '/home/runner/actions-runner/cached/2.338.2/_diag/Worker_20261102-062353-utc.log'

@fanquake

Copy link
Copy Markdown
Member

Isn't that kind of issue a problem with the nightly build infrastructure itself? My recollection is that a lot, if not most, of the issues from that repo have been of a similar nature (timeouts, OOM, out of space, flakiness/can't reproduce) and point to it being under-resourced/unstable, rather than some fundamental problem with these operating systems?

@maflcko

maflcko commented Nov 12, 2026

Copy link
Copy Markdown
Member

Right, so if this pull is merged, we'll have to deal with a flood of meaningless false reports instead of any real issues that would happen on those systems.

@fanquake

Copy link
Copy Markdown
Member

Why? We can pay for (reliable) CPU and enough disk space to be able to properly run tests; and I don't see why anything would be merged if the expectation was it'd just produce pointless noise.

If anything, it would seem better to have the tests run properly here, than improperly in a different repo, and still have to deal with all the false reports?

@maflcko

maflcko commented Nov 12, 2026

Copy link
Copy Markdown
Member

Ok, I am not sure if the better hardware will propagate into the double-nested VM (if the inner VM is set up with fixed hard-coded resources), but I guess it seems fine to try and then revert if it doesn't work.

@pinheadmz

Copy link
Copy Markdown
Member

concept ACK, especially with the recent socket stuff the nightly BSD builds as well as individual reviewers are finding things. If we support BSDs I think it would be great to have CI, will review.

@maflcko

maflcko commented Nov 13, 2026

Copy link
Copy Markdown
Member

Maybe there can be a temp commit on top to spawn a matrix with 100 or 200 tasks for freebsd (or whatever is added) to see if there are any nested vm crashes?

@vasild

vasild commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Concept ACK

@willcl-ark

Copy link
Copy Markdown
Member Author

I will drop the vm caches here.

I think I will also (optimistically) rebase this on top of #36916 which I think addresses the port collisions correctly (and certainly a lot more cleanly than the previous hack in this PR).

@hebasto

hebasto commented Nov 19, 2026

Copy link
Copy Markdown
Member

In my year of experience with this action, I really can't see the need for either of them. Starting a FreeBSD VM with a non-trivial prepare input usually takes under 2 minutes.

I will drop the vm caches here.

For this job it takes 7..8 minutes. It seems acceptable for me.

@willcl-ark

Copy link
Copy Markdown
Member Author

going to leave this in draft to focus on #36916 first

@willcl-ark
willcl-ark marked this pull request as draft November 19, 2026 16:45
hebasto added a commit that referenced this pull request Nov 27, 2026
41c4df2 test: avoid BSD ephemeral-port collisions in HTTP clients (will)

Pull request description:

  While stress-testing #36147 I noticed sporadic port collisions still occurring on FreeBSD.

  `set_ephemeral_port_range()` keeps the source port out of the test port range, but only for sockets the framework creates itself. Python's `http.client` creates its sockets internally, so RPC and REST connections can still be given a source port inside the test range. A connection to a closed port can then connect to itself. For example, the wrong-RPC-port startup check failed with `BadStatusLine: POST / HTTP/1.1` because the client read back its own request.

  This change adds a `netutil.HTTPConnection` subclass that sets the port range before connecting, and uses it in `AuthServiceProxy` and in the tests that open HTTP connections directly.

  HTTPS is left unchanged because we don't serve RPC over TLS so it seems unnecessary.

ACKs for top commit:
  hebasto:
    re-ACK 41c4df2.

Tree-SHA512: c39a61977e5b00907bda34040addf9cfce9c7502b08d7879e2fe504351d79d89b223ec487840a40296187b82e8dc2b0844d5060467b8c6c5b2e5886daae3ee8c
FreeBSD lsof can emit the following warning during parallel tests:

    lsof: WARNING -- reading lockf list failed: Cannot allocate memory

The functional test runner treats nonempty stderr as failure even when a
test exits successfully.

The lock information is separate from the TCP listener addresses queried
by get_bind_addrs, so suppress lsof warnings for this query while
retaining the tests' socket-address assertions.
@hebasto

hebasto commented Nov 27, 2026

Copy link
Copy Markdown
Member

going to leave this in draft to focus on #36916 first

Maybe undraft?

@willcl-ark

Copy link
Copy Markdown
Member Author

Undrafted.

The one failing run previously seems to have just timed out (or errored) on pkg install. Could be a server error or something else. I considered adding a retry here, but according to the manpage pkg install already retries 3 times.

I did make a small tweak to the python packages though, selecting them by python version. This might be error-prone (and we might therefore want to revert), but it does avoid downloading these packages for multiple python versions; apparently these packages cover 6 or 7 python versions each?

@vasild

vasild commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

it does avoid downloading these packages for multiple python versions

When would that happen? Do I understand correctly that sometimes it would download py312-sqlite3 and in another occasion e.g. py314-sqlite3?

Keep NetBSD and OpenBSD on their existing cross-compiled jobs.

Run the full test suite natively on FreeBSD.
Because the FreeBSD job sets DANGER_RUN_CI_ON_HOST=1, 02_run_container.py
does not assign BIND_TEST_ROUTABLE_IPV4 or BIND_TEST_ROUTABLE_IPV6, so
feature_bind_port_discover.py skips by default. Add its documented
routable aliases to the VM's default interface during preparation so the
test runs and exercises FreeBSD's getifaddrs discovery path.
Repeat the native FreeBSD job to assess selective cache retrieval without
spending runner time on unrelated jobs. Keep all temporary trial controls
in this commit so dropping it restores the normal CI configuration.
@willcl-ark

Copy link
Copy Markdown
Member Author

it does avoid downloading these packages for multiple python versions

When would that happen? Do I understand correctly that sometimes it would download py312-sqlite3 and in another occasion e.g. py314-sqlite3?

Ah not quite (but also not quite how I originally understood it, too):

See for example https://github.com/freebsd/freebsd-ports/blob/3c9affb17b35421840c24a176ebe2c8883a67ffe/databases/py-sqlite3/Makefile#L20 which specifies USE_PYTHON= allflavors autoplist pep517 (feeding into this).

So databases/py-sqlite3 requests all available flavours of Python’s sqlite3 module, which downloads multiple python interpreters AFAICT, e.g. in the failed run: 3.11, 3.12, 3.13, 3.13t, 3.14, 3.14t, and 3.15. link

The other python packages do not set this in their builds/do this. I moved all python packages to this type only for consistency.

@DrahtBot

DrahtBot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task FreeBSD 24: https://github.com/bitcoin/bitcoin/actions/runs/46913037948/job/143573391103
LLM reason (✨ experimental): functional_test_fail: feature_torcontrol.py failed because its mock Tor service could not bind the control port: Address already in use.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • Intermittent network issues can occur; re-run CI for now, and report the issue if they keep happening.

  • A functional or integration test failure may be intermittent or unrelated to this pull request.
    If no dedicated issue thread exists, create a new one to track it.

Leave a comment here, if you need help tracking down a confusing failure.

@vasild

vasild commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Right, databases/py-sqlite3 pulls in all flavors which even if benign looks excessive. Can use databases/py-sqlite3@py314 instead and define py314 in a separate variable and suffix all python packages with it, so that when it has to be changed, it's only in one place.

Maybe omit lang/python3 because its proper version will be pulled by the other py packages, e.g. by databases/py-sqlite3@py314 or py314-sqlite3.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants