fix: fix nodejs env missing some system call #204
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix issue langgenius/dify#28932
The Problem with ActKillProcess
ActKillProcess has issues with the TSYNC flag (synchronizes filter across threads) that causes spurious process kills. This appears to be a known issue with libseccomp or kernel behavior in certain scenarios.
The Solution
Use ActErrno.SetReturnCode(1) which:
internal/static/nodejs_syscall/syscalls_amd64.go
For newer syscalls like clone3 (435), rseq (293), statx (291), and io_uring (425-427):
This FAILS with libseccomp 2.6.0:
syscall, _ := sg.GetSyscallFromName("clone3")
ctx.AddRule(syscall, sg.ActAllow) // Error!
This WORKS - using raw number:
ctx.AddRule(sg.ScmpSyscall(435), sg.ActAllow) // Success
Reason: libseccomp 2.6.0 has a known limitation where it can resolve the syscall name but fails to add the rule for newer syscalls. Using raw syscall numbers bypasses this bug.
After chroot(), the filesystem root changes. Node.js's TLS modules (https, undici/fetch) expect CA certificates at:
While these files are copied into the chroot via REQUIRED_FS, Node.js doesn't automatically find them in the chrooted environment.
The Solution
Two-layer approach:
Environment variable (nodejs.go):
cmd.Env = append(cmd.Env, "NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt"), Helps https module find certificates
Explicit configuration (prescript.js):
const caCert = fs.readFileSync('/etc/ssl/certs/ca-certificates.crt', 'utf8')
For https module
https.globalAgent.options.ca = caCert
For undici (fetch)
const { setGlobalDispatcher, Agent } = globalThis.undici
const agent = new Agent({ connect: { ca: caCert } })
setGlobalDispatcher(agent)
Ensures fetch (undici) can verify TLS certificates
Why Both Are Needed
before bugfix
test below
in amd64 env
in arm64 env
in docker env