kj fibers are not supported on musl libc #955

Closed
opened 2025-08-09 11:41:00 +00:00 by alois31 · 7 comments
Member

Describe the bug

Musl does not implement the setcontext function, which is required by kj fibers that were presumably introduced in db0ed505e9.

Steps To Reproduce

  1. Try to build a static Lix (e.g. pkgsStatic.lixPackageSets.git.lix from https://github.com/NixOS/nixpkgs/pull/424775)
  2. Observe failing tests in the installCheckPhase, with the following excerpt from the log:
Lix crashed. This is a bug. We would appreciate if you report it along with what caused it at https://git.lix.systems/lix-project/lix/issues with the following information included:

Exception: kj::ExceptionImpl: kj/async.c++:1543: unimplemented: Fibers are not implemented on this platform because its C library lacks setcontext() and friends. If you'd like to see fiber support added, file a bug to let us know. We can likely make it happen using assembly, but didn't want to try unless it was actually needed.
Stack trace:
 0# 0x000000000066DDB6
 1# 0x0000000000662883
 2# 0x0000000000EFCA18
 3# 0x0000000001B36CBA
 4# 0x0000000000407B5A
 5# 0x000000000042F6CE
 6# 0x0000000000BF1078
 7# 0x0000000000A35470
 8# 0x0000000001033927
 9# 0x000000000103499C
10# 0x000000000102D888
11# 0x00000000004C849A
12# 0x00000000004C7C3E
13# 0x00000000004C5E70
14# 0x0000000000F0E046
15# 0x000000000051123E
16# 0x0000000000513F15
17# 0x0000000000EF7086
18# 0x0000000000513B02
19# 0x0000000001BEE530

remote-store.sh: line 6:  4739 Aborted                    (core dumped) nix --store ssh-ng://localhost?remote-store=$TEST_ROOT/other-store doctor
++(remote-store.sh:6) onError

Expected behavior

Lix is compatible with musl libc.

nix --version output

Not applicable since the build fails. The build was attempted on commit 8bbd5e1d0d.

## Describe the bug Musl does not implement the `setcontext` function, which is required by kj fibers that were presumably introduced in https://git.lix.systems/lix-project/lix/commit/db0ed505e9353faf46c0a01a947586c4e8811937. ## Steps To Reproduce 1. Try to build a static Lix (e.g. `pkgsStatic.lixPackageSets.git.lix` from https://github.com/NixOS/nixpkgs/pull/424775) 2. Observe failing tests in the `installCheckPhase`, with the following excerpt from the log: ``` Lix crashed. This is a bug. We would appreciate if you report it along with what caused it at https://git.lix.systems/lix-project/lix/issues with the following information included: Exception: kj::ExceptionImpl: kj/async.c++:1543: unimplemented: Fibers are not implemented on this platform because its C library lacks setcontext() and friends. If you'd like to see fiber support added, file a bug to let us know. We can likely make it happen using assembly, but didn't want to try unless it was actually needed. Stack trace: 0# 0x000000000066DDB6 1# 0x0000000000662883 2# 0x0000000000EFCA18 3# 0x0000000001B36CBA 4# 0x0000000000407B5A 5# 0x000000000042F6CE 6# 0x0000000000BF1078 7# 0x0000000000A35470 8# 0x0000000001033927 9# 0x000000000103499C 10# 0x000000000102D888 11# 0x00000000004C849A 12# 0x00000000004C7C3E 13# 0x00000000004C5E70 14# 0x0000000000F0E046 15# 0x000000000051123E 16# 0x0000000000513F15 17# 0x0000000000EF7086 18# 0x0000000000513B02 19# 0x0000000001BEE530 remote-store.sh: line 6: 4739 Aborted (core dumped) nix --store ssh-ng://localhost?remote-store=$TEST_ROOT/other-store doctor ++(remote-store.sh:6) onError ``` ## Expected behavior Lix is compatible with musl libc. ## `nix --version` output Not applicable since the build fails. The build was attempted on commit https://git.lix.systems/lix-project/lix/commit/8bbd5e1d0df9c31b4d86ba07bc85beb952e42ccb.
Owner

fyi we could fix the capnproto derivation to support this via libucontext: https://github.com/capnproto/capnproto/issues/1167

fyi we could fix the capnproto derivation to support this via libucontext: https://github.com/capnproto/capnproto/issues/1167
Author
Member

https://github.com/kaniini/libucontext?tab=readme-ov-file#caveats, the fact that pkgsStatic.libucontext fails to build due to trying to create a dynamic library, and that another library-based stackful coroutine implementation was already removed do not exactly make me hopeful.

https://github.com/kaniini/libucontext?tab=readme-ov-file#caveats, the fact that `pkgsStatic.libucontext` fails to build due to trying to create a dynamic library, and that another library-based stackful coroutine implementation was already removed do not exactly make me hopeful.
Owner

I'm working on this, there's a bunch of really dumb bugs in the nixpkgs packaging of that. Will send you the pr.

I'm working on this, there's a bunch of really dumb bugs in the nixpkgs packaging of that. Will send you the pr.
Owner

there's currently only one fiber user in the codebase, and its parent function (performOp in the daemon) is sync and fully linear. that user can be converted to not using fibers and calling fcntl on the connection. adding a dubiously-complete library as a dependency seems like a more dangerous move than adding a few fcntl calls, especially since we know from the client side that this works perfectly well.

we were planning on adding another user (optimizing sqlite db file lock acquisition), but that can be fully optional and just not used if fibers aren't available.

there's currently only one fiber user in the codebase, and its parent function (`performOp` in the daemon) is sync and fully linear. that user can be converted to not using fibers and calling fcntl on the connection. adding a dubiously-complete library as a dependency seems like a more dangerous move than adding a few fcntl calls, especially since we know from the client side that this works perfectly well. we were planning on adding another user (optimizing sqlite db file lock acquisition), but that can be fully optional and just not used if fibers aren't available.
Author
Member

@jade wrote in #955 (comment):

I'm working on this, there's a bunch of really dumb bugs in the nixpkgs packaging of that. Will send you the pr.

If that's just a nixpkgs bug that should fully resolve the pkgsStatic.libucontext build failure concern. However, to make the "library-based stackful coroutine implementation" concern more explicit, I remember boost context being thrown out to much rejoicing. Are we sure this one is going to turn out better?

@jade wrote in https://git.lix.systems/lix-project/lix/issues/955#issuecomment-13930: > I'm working on this, there's a bunch of really dumb bugs in the nixpkgs packaging of that. Will send you the pr. If that's just a nixpkgs bug that should fully resolve the `pkgsStatic.libucontext` build failure concern. However, to make the "library-based stackful coroutine implementation" concern more explicit, I remember boost context being thrown out to much rejoicing. Are we sure this one is going to turn out better?
Owner
https://github.com/NixOS/nixpkgs/pull/432321 https://github.com/NixOS/nixpkgs/pull/432323 here's the two fix prs we have to land and backport
Owner

Ib4e1531fe920847d8e30a42e8df393ace549f52e defaults to not using fibers on musl now just to be safe

Ib4e1531fe920847d8e30a42e8df393ace549f52e defaults to not using fibers on musl now just to be safe
Sign in to join this conversation.
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#955
No description provided.