Skip to content

Improve nodejs stack size limit heuristic. #1122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,17 +891,24 @@ func runNode(script string, args []string, dir string, quiet bool, out io.Writer
// - OS process limit
// - Node.js (V8) limit
//
// GopherJS fetches the current OS process limit, and sets the
// Node.js limit to the same value. So both limits are kept in sync
// and can be controlled by setting OS process limit. E.g.:
// GopherJS fetches the current OS process limit, and sets the Node.js limit
// to a value slightly below it (otherwise nodejs is likely to segfault).
// The backoff size has been determined experimentally on a linux machine,
// so it may not be 100% reliable. So both limits are kept in sync and can
// be controlled by setting OS process limit. E.g.:
//
// ulimit -s 10000 && gopherjs test
//
cur, err := sysutil.RlimitStack()
if err != nil {
return fmt.Errorf("failed to get stack size limit: %v", err)
}
allArgs = append(allArgs, fmt.Sprintf("--stack_size=%v", cur/1000)) // Convert from bytes to KB.
cur = cur / 1024 // Convert bytes to KiB.
defaultSize := uint64(984) // --stack-size default value.
if backoff := uint64(64); cur > defaultSize+backoff {
cur = cur - backoff
}
allArgs = append(allArgs, fmt.Sprintf("--stack_size=%v", cur))
}

allArgs = append(allArgs, script)
Expand Down