Skip to content

Conversation

@jwj1342
Copy link

@jwj1342 jwj1342 commented Nov 13, 2025

Summary

Resolve segmentation faults and bus errors during webpack production builds by implementing memory optimizations.

Problem

When building the webpack production bundle, developers encounter build failures on high-core-count systems:

  • Exit code 135 (bus error) or 139 (segmentation fault)
  • Error occurs during the webpack compilation step: npm run webpack:production

Root Cause: Webpack's TerserPlugin and CssMinimizerPlugin spawn parallel workers equal to CPU core count. On systems with many cores (e.g., 32 cores), this causes memory exhaustion as each worker consumes
significant RAM simultaneously.

Solution

This PR implements two optimizations:

  1. Increase Node.js heap size (services/web/Dockerfile)

    • Set --max-old-space-size=12288 (12GB heap)
    • Allows Node.js to handle larger memory requirements during build
  2. Limit parallel workers (services/web/webpack.config.prod.js)

    • Set parallel: 2 for both TerserPlugin and CssMinimizerPlugin
    • Reduces peak memory usage by limiting concurrent compression workers
    • Maintains reasonable build times while preventing crashes

Testing

  • ✅ Verified successful webpack production build on 32-core system (previously failing)
  • ✅ No increase in build time beyond acceptable limits
  • ✅ Generated bundle integrity confirmed

Trade-offs

  • Slightly longer build times due to reduced parallelism (acceptable for stability)
  • Increased memory allocation requirement (12GB heap, reasonable for modern systems)

Create initial package.json for @overleaf/eslint-plugin library to support
ESLint plugin development within the Overleaf monorepo workspace structure.

This establishes the foundation for custom ESLint rules and configurations
that can be shared across services.
Resolve segmentation faults and bus errors during webpack production builds
by implementing two key optimizations:

1. Increase Node.js heap size to 12GB (--max-old-space-size=12288)
2. Limit parallel workers in TerserPlugin and CssMinimizerPlugin to 2

Without these changes, webpack's default behavior of spawning workers equal
to CPU core count can cause memory exhaustion on high-core-count systems,
resulting in build failures with exit codes 135 (bus error) or 139
(segmentation fault).

This fix allows successful builds while maintaining reasonable build times.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant