Files
bun.sh/test/regression
Dylan Conway edb49a6c2f fix(compile): fix native module export corruption with multiple NAPI modules
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>
2026-01-14 19:40:37 +00:00
..