Frequent build crashes related to libxml2

My builds frequently (but not always) crash with the following stack trace:

11:18:45 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
11:18:45 AM: *** Signal 11: Backtracing from 0x7fdf486d40d9... done ***
11:18:45 AM: *** Program crashed: Bad pointer dereference at 0x000000007478657c ***
11:18:45 AM: Thread 0 "Loopwerk":
11:18:45 AM: 0      0x00007fdf4b3ee5eb <unknown> in libc.so.6
11:18:45 AM: 1 [ra] 0x00007fdf4bd940d8 _dispatch_sigsuspend + 23 in libdispatch.so
11:18:45 AM: 2 [ra] 0x00007fdf4b3d31d6 <unknown> in libc.so.6
11:18:45 AM: 3 [ra] 0x00007fdf4b3d328b <unknown> in libc.so.6
11:18:45 AM: Thread 1 crashed:
11:18:45 AM: 0      0x00007fdf486d40d9 <unknown> in libxml2.so.2.9.14
11:18:45 AM: 1 [ra] 0x00007fdf486e1ead <unknown> in libxml2.so.2.9.14
11:18:45 AM: Thread 2:
11:18:45 AM: 0      0x00007fdf4b4d3042 <unknown> in libc.so.6
11:18:45 AM: 1 [ra] 0x00007fdf4bd9b405 _dispatch_event_loop_drain + 52 in libdispatch.so
11:18:45 AM: Thread 3:
11:18:45 AM: 0      0x00007fdf4b441d71 <unknown> in libc.so.6
11:18:45 AM: 1 [ra] 0x00007fdf4b44dd93 <unknown> in libc.so.6
11:18:45 AM: Registers:
11:18:45 AM: rax 0x0000000074786574  1954047348
11:18:45 AM: rdx 0x0000000000000000  0
11:18:45 AM: rcx 0x000000007478659c  1954047388
11:18:45 AM: rbx 0x0000000000000000  0
11:18:45 AM: rsi 0x00007fdf404ddf80  4c 6f 6f 70 77 65 72 6b 00 00 00 00 00 00 00 00  Loopwerk········
11:18:45 AM: rdi 0x00007fdf40000090  d0 c7 58 40 df 7f 00 00 20 9d 43 40 df 7f 00 00  ÐÇX@ß··· ·C@ß···
11:18:45 AM: rbp 0x00007fdf44ac45b0  e0 45 ac 44 df 7f 00 00 ad 1e 6e 48 df 7f 00 00  àE¬Dß···­·nHß···
11:18:45 AM: rsp 0x00007fdf44ac4560  00 69 6d 4b df 7f 00 00 90 00 00 40 df 7f 00 00  ·imKß······@ß···
11:18:45 AM:  r8 0x0000000000000000  0
11:18:45 AM:  r9 0x80000000ffffffff  9223372041149743103
11:18:45 AM: r10 0x0000000100000000  4294967296
11:18:45 AM: r11 0x0000000200000000  8589934592
11:18:45 AM: r12 0x00007fdf40000090  d0 c7 58 40 df 7f 00 00 20 9d 43 40 df 7f 00 00  ÐÇX@ß··· ·C@ß···
11:18:45 AM: r13 0x00007fdf4884d600  30 6d 45 4b df 7f 00 00 00 01 00 00 00 00 00 00  0mEKß···········
11:18:45 AM: r14 0x00007fdf404d03c0  50 ba 4e 40 df 7f 00 00 01 00 00 00 00 00 00 00  PºN@ß···········
11:18:45 AM: r15 0x00007fdf404f4190  00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00  ················
11:18:45 AM: rip 0x00007fdf486d40d9  48 39 78 08 73 31 48 8b 00 48 85 c0 75 e9 48 8b  H9x·s1H··H·ÀuéH·
11:18:45 AM: rflags 0x0000000000010216  AF PF
11:18:45 AM: cs 0x0033  fs 0x0000  gs 0x0000
11:18:45 AM: Images (78 omitted):
11:18:45 AM: 0x00007fdf4866d000–0x00007fdf48801b4d e8570b8e62a2bf44888a990d90526a4931817b62 libxml2.so.2.9.14 /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.14
11:18:45 AM: 0x00007fdf4b3a9000–0x00007fdf4b558cb9 42c84c92e6f98126b3e2230ebfdead22c235b667 libc.so.6         /usr/lib/x86_64-linux-gnu/libc.so.6
11:18:45 AM: 0x00007fdf4bd5e000–0x00007fdf4bd9c9c1 <no build ID>                            libdispatch.so    /opt/buildhome/.swiftenv/versions/6.0.1/usr/lib/swift/linux/libdispatch.so
11:18:45 AM: Backtrace took 0.01s

My site is built using Swift, and it uses Apple’s XMLElement and XMLDocument. This in turn relies on libxml2, which is installed on Netlify (I am using Ubuntu 24.04). Like I said, sometimes the builds crash, and then a retry works. I’d say it fails once every 5 builds or so. It’s rather annoying and I don’t know what to do about this?

hey @Loopwerk , can you share a link to the site so we can take a closer look?

It’s loopwerk-io. Here are links to some of the crashed builds:

thanks! can you confirm whether you’re also seeing these intermittent build errors locally as well? to your point this looks to be (so far) an issue moreso with libxml2 crashing during XML parsing than an issue with the build process itself. if not, can you also let us know whether you’re using the same Swift version on the deploy site as you are locally?

I’m never seeing these errors locally, but I am on macOS and there I don’t think it even uses libxml2.

I guess you’re right that the bug probably lies with libxml2 and not with Netlify.