mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
When compiling with `bun build --compile`, multiple native NAPI modules would have their exports corrupted on Linux. The second module would incorrectly inherit the first module's exports. Root cause: On Linux, we used memfd_create as an optimization to avoid writing temp files. After dlopen loaded the first module, we closed the memfd. When loading the second module, memfd_create reused the same fd number, creating an identical path `/proc/self/fd/N`. Since dlopen caches by path, it returned the cached handle from the first module instead of loading the second module. This bug occurs when loading multiple native modules in quick succession, as the fd number is likely to be reused immediately after being closed. Fix: Disable the memfd optimization and always use temp files, which have unique paths and don't trigger dlopen's path-based caching. Fixes https://github.com/oven-sh/bun/issues/26045 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>