100% cpu and huge strace output doing `yarn build` in linux/amd64 container on macos arm64 host

I am running a linux/amd64 container in Docker on an arm64 macbook running macos 14.1. Within that container I am doing a yarn build (using node.js and other tools) on a codebase I am developing which takes a couple of minutes to run outside the container. Inside the container it starts normally, but after a minute of normal behavior the progress indicator stops animating and it spikes the cpu to 100% then does nothing else indefinitely (24+ hours). strace tells me that when it gets stuck it switches from vaguely normal syscall behavior (excerpt below) to gigabyte-long trace output lines that look something like this:

sendmsg(80482544, {msg_name={sa_family=0xfcf8 /* AF_??? */, sa_data="\2\2\0\0"}, msg_namelen=6, msg_iov=[{iov_base=0x2000000070, iov_len=
177}, {iov_base="\0\0\0\0\0\0\0\0A\0\0\0\0\0\0\0P\335-\6\0\0\0\0G\0\0\0\0\0\0\0"..., iov_len=107487776}, {iov_base="&\0\0\0:\0\0\0h\0\0\0
o\0\0\0v\0\0\0e\0\0\0r\0\0\0,\0\0\0"..., iov_len=111065600}, {iov_base=0x30, iov_len=64}, {iov_base="", iov_len=0}, {iov_base=0x48, iov_l
en=72}, {iov_base=NULL, iov_len=284}, {iov_base=0x10, iov_len=65}, {iov_base="0\0\0\0\0\0\0\0A\0\0\0\0\0\0\0\20P\314\7\0\0\0\0\266\6\0\0\
0\0\0\0"..., iov_len=110753520}, {iov_base=0x4c, iov_len=76}, {iov_base=NULL, iov_len=80397408}, {iov_base=0x100, iov_len=96}, {iov_base=
"\0\0\0\0\0\0\0\0!\2\0\0\0\0\0\0\220\362\21\10\0\0\0\0\20\200\273\4\0\0\0\0"..., iov_len=498216206446}, {iov_base=0x700000002d, iov_len=4

I think something is going very wrong with Rosetta (Apple’s arm64/amd64 translation layer) here, but I’m not sure where to find troubleshooting help with that. I’d like to get deeper before reporting a vague unreproducible bug (I can’t share the source code I’m trying to build).

Here’s the end of the normal-ish strace output before the long sendmsg lines start:

syscall_0x8550320(0x3, 0x4cc10f0, 0x4ba0e20, 0, 0x4ba0dc0, 0x62) = 0
syscall_0x4ba0de8(0x80, 0xca, 0xa636, 0, 0x4ba0dc0, 0x62) = 0
syscall_0x80d44e0(0x3, 0x4cc10f0, 0x4ba0e20, 0, 0x4ba0dc0, 0x62) = 0
syscall_0x4ba0de8(0x4cc10f0, 0x1, 0x6837728, 0, 0x4ba0dc0, 0x62) = 0
syscall_0x6837580(0x4cc10f0, 0x3, 0x4ba0e20, 0, 0x4ba0dc0, 0x62) = 0
pread64(0, NULL, 0, 0)                  = 281473338258152
pread64(2560, NULL, 0, 0)               = 281473338258152
syscall_0x5554ffff7530(0x5554ffff7330, 0x3c000, 0xffff97683000, 0, 0, 0xe2) = 0xffff9767b781
syscall_0x5554ffff7530(0x5554ffff7330, 0x3c000, 0xffff97503000, 0, 0, 0xe2) = 0xffff974e9020
syscall_0x4ba0de8(0x4cc10f0, 0x1, 0x82c2508, 0, 0x4ba0dc0, 0x62) = 0
syscall_0x4ba0de8(0x80, 0xca, 0xa639, 0, 0x4ba0dc0, 0x62) = 0
syscall_0x4ba0de8(0x4cc10f0, 0x1, 0x7f59148, 0, 0x4ba0dc0, 0x62) = 0
dup2(80482544, 133533688)               = 0
syscall_0x4ba0de8(0x4cc10f0, 0x1, 0x80d8ba8, 0, 0x4ba0dc0, 0x62) = 0
pause()                                 = 0
syscall_0x4ba0de8(0x4cc10f0, 0x1, 0x6fe9988, 0, 0x4ba0dc0, 0x62) = 0
nanosleep({tv_sec=33642704, tv_nsec=140737484682256}, 0x6fe9838) = 0
syscall_0x4ba0de8(0x80, 0xca, 0xa63d, 0, 0x4ba0dc0, 0x62) = 0
alarm(80482544)                         = 0
syscall_0x4ba0de8(0x4cc10f0, 0x1, 0x75d8f28, 0, 0x4ba0dc0, 0x62) = 0
getitimer(0x4cc10f0 /* ITIMER_??? */, {it_interval={tv_sec=123571584, tv_usec=6}, it_value={tv_sec=5299989643273, tv_usec=2}}) = 0
syscall_0x4ba0de8(0x4cc10f0, 0x1, 0x4c95318, 0, 0x4ba0dc0, 0x62) = 0
setitimer(0x4cc10f0 /* ITIMER_??? */, {it_interval={tv_sec=80302448, tv_usec=6}, it_value={tv_sec=257, tv_usec=100434032}}, {it_interval=
{tv_sec=33750264, tv_usec=98381824}, it_value={tv_sec=80482544, tv_usec=0}}) = 0
syscall_0x4ba0de8(0x80, 0xca, 0xa640, 0, 0x4ba0dc0, 0x62) = 0
getpid()                                = 0
syscall_0x4ba0de8(0x4cc10f0, 0x1, 0x809e7e8, 0, 0x4ba0dc0, 0x62) = 0
sendfile(80482544, 134866584, [33750264], 0) = 0
syscall_0x4ba0de8(0x4cc10f0, 0x1, 0x7c8d1e8, 0, 0x4ba0dc0, 0x62) = 0
connect(80482544, {sa_family=0xd040 /* AF_??? */, sa_data="\310\7\0\0\0\0\6\0\0\0\0\0\0\0000\0\0\0\0\0\0\0\320\320\310\7\0\0\0\0\20\275,\
7\0\0\0\0\340\321\310\7\0\0\0\0`\322\310\7\0\0\0\0P\0\0\0\0\0\0\0\2\0\0\0\0\0\0\0 \16\272\4\0\0\0\0\200\\\260\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0K\0\0\0\0\0\0\0\244\201\0\0\0\0\0\0"}, 130601024) = 0
syscall_0x4ba0de8(0x4cc10f0, 0x1, 0x8281e28, 0, 0x4ba0dc0, 0x62) = 0
accept(80482544, {sa_family=0x1c80 /* AF_??? */, sa_data="(\10\0\0\0\0\6\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\2\0\0\0\0\0\0\0 \16\272\4\0\0\0\0\200\\\260\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0K\0\0\0\0\0\0\0\244\201\0\0\0\0\0\0"}, [33750264]) = 0
syscall_0x4ba0de8(0x80, 0xca, 0xa644, 0, 0x4ba0dc0, 0x62) = 0
sendto(80482544, "\220u\364\7\0\0\0\0\6\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 133461392, 0, {sa_family=0x4c91 /* AF_??? */, 
sa_data="\1\0\0\0\0\0\211L\1\0\0\0\0\0\6\0\0\0\0\0\0\0\3\0\0\0\0\0\0\0\20\0\0\0\32\0\0\0\0\0\0\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
0\0\0\0\0\0\0\0 \16\272\4\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 98) = 0
syscall_0x4ba0de8(0x4cc10f0, 0x1, 0x7f7c8c8, 0, 0x4ba0dc0, 0x62) = 0
recvfrom(80482544, "", 133678880, 0, 0x4ba0dc0, 0x62) = 0
syscall_0x4ba0de8(0x4cc10f0, 0x1, 0x747bcc8, 0, 0x4ba0dc0, 0x62) = 0
socket(0x4cc10f0 /* AF_??? */, SOCK_NONBLOCK|0x747b378, 122141472) = 0
syscall_0x4ba0de8(0x4cc10f0, 0x1, 0x69ebaf8, 0, 0x4ba0dc0, 0x62) = 0