Skip to content
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

Bus error (webpack) when building Gitea #29058

Closed
bagasme opened this issue Feb 5, 2024 · 12 comments · Fixed by #29070
Closed

Bus error (webpack) when building Gitea #29058

bagasme opened this issue Feb 5, 2024 · 12 comments · Fixed by #29070
Labels
type/bug type/upstream This is an issue in one of Gitea's dependencies and should be reported there

Comments

@bagasme
Copy link
Contributor

bagasme commented Feb 5, 2024

Description

Hi,

I'm trying to build Gitea on commit 4bb1fcd, following build instructions. Node.js used is v18.19.0.

As I run make, the build stopped on webpack where webpack core dumped due to bus error (AFAIK, it because my Intel core i3 haswell processor can't attempt memory requests from node).

After examining the dump info (via coredumpctl info), it turns out that lightningcss module causes the webpack error.

This build issue is also reproduced on node v20.11.0.

Gitea Version

commit 4bb1fcd

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

https://gist.github.com/bagasme/d58a38beac308a20aa3b40dda2285021

Screenshots

n/a

Git Version

n/a

Operating System

Arch Linux

How are you running Gitea?

Building from source (node v18.19.0, go 1.21.6).

npx webpack info output:


  System:
    OS: Linux 6.8 Arch Linux
    CPU: (4) x64 Intel(R) Core(TM) i3-4030U CPU @ 1.90GHz
    Memory: 1.31 GB / 3.73 GB
  Binaries:
    Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
    npm: 10.2.3 - ~/.nvm/versions/node/v18.19.0/bin/npm
  Packages:
    add-asset-webpack-plugin: 2.0.1 => 2.0.1 
    css-loader: 6.10.0 => 6.10.0 
    esbuild-loader: 4.0.3 => 4.0.3 
    license-checker-webpack-plugin: 0.2.1 => 0.2.1 
    lightningcss-loader: 2.1.0 => 2.1.0 
    monaco-editor-webpack-plugin: 7.1.0 => 7.1.0 
    vue-loader: 17.4.2 => 17.4.2 
    webpack: 5.90.1 => 5.90.1 
    webpack-cli: 5.1.4 => 5.1.4 

Database

None

@wxiaoguang
Copy link
Contributor

I guess it is a upstream problem (as you mentioned: lightningcss), so Gitea could do nothing IMO?

Could you report the problem to upstream?

@wxiaoguang wxiaoguang added type/bug type/upstream This is an issue in one of Gitea's dependencies and should be reported there and removed type/bug labels Feb 5, 2024
@silverwind
Copy link
Member

silverwind commented Feb 5, 2024

The intention is that it should fall back to esbuild in case lightningcss crashes, but it appears we only catch startup crashes, not runtime crashes:

gitea/webpack.config.js

Lines 58 to 62 in 6992ef9

// in case lightningcss fails to load, fall back to esbuild for css minify
let LightningCssMinifyPlugin;
try {
({LightningCssMinifyPlugin} = await import('lightningcss-loader'));
} catch {}

We could also just remove lightningcss if this turns out to be not fixable from our end. It will give slightly larger CSS files, but esbuild is arguably much more battle-tested.

@silverwind
Copy link
Member

silverwind commented Feb 5, 2024

@bagasme Can you try if this changes anything?

NODE_OPTIONS="--max-old-space-size=4096" make webpack

This is more memory than your system has but I assume you have a swap file.

@bagasme
Copy link
Contributor Author

bagasme commented Feb 5, 2024

@bagasme Can you try if this changes anything?

NODE_OPTIONS="--max-old-space-size=4096" make webpack

This is more memory than your system has but I assume you have a swap file.

Nope. I can still reproduce the webpack bus error.

@silverwind
Copy link
Member

silverwind commented Feb 5, 2024

Hmm, so I guess your system may have too little memory for lightningcss to run. Do you have a swap file, and if not, create one? I would recomment at least 8GB size.

@bagasme
Copy link
Contributor Author

bagasme commented Feb 5, 2024

I guess it is a upstream problem (as you mentioned: lightningcss), so Gitea could do nothing IMO?

Could you report the problem to upstream?

Done at parcel-bundler/lightningcss#671.

@bagasme
Copy link
Contributor Author

bagasme commented Feb 5, 2024

Hmm, so I guess your system may have too little memory for lightningcss to run. Do you have a swap file, and if not, create one? I would recomment at least 8GB size.

Yes, I have 4GB RAM + 4.41GiB swap.

@silverwind
Copy link
Member

Thanks, so let's see what comes out of the issue. I'm still leaning towards removing lightningcss, it just seems not stable enough.

@silverwind
Copy link
Member

@bagasme can you try this patch on the affected machine?

diff --git a/webpack.config.js b/webpack.config.js
index c4b140a12b..16afa0ff9c 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -54,14 +54,8 @@ const filterCssImport = (url, ...args) => {

   return true;
 };

-// in case lightningcss fails to load, fall back to esbuild for css minify
-let LightningCssMinifyPlugin;
-try {
-  ({LightningCssMinifyPlugin} = await import('lightningcss-loader'));
-} catch {}
-
 /** @type {import("webpack").Configuration} */
 export default {
   mode: isProduction ? 'production' : 'development',
   entry: {
@@ -105,14 +99,11 @@ export default {
     minimizer: [
       new EsbuildPlugin({
         target: 'es2020',
         minify: true,
-        css: !LightningCssMinifyPlugin,
+        css: true,
         legalComments: 'none',
       }),
-      LightningCssMinifyPlugin && new LightningCssMinifyPlugin({
-        sourceMap: sourceMaps === 'true',
-      }),
     ],
     splitChunks: {
       chunks: 'async',
       name: (_, chunks) => chunks.map((item) => item.name).join('-'),

@bagasme
Copy link
Contributor Author

bagasme commented Feb 6, 2024

@bagasme can you try this patch on the affected machine?

diff --git a/webpack.config.js b/webpack.config.js
index c4b140a12b..16afa0ff9c 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -54,14 +54,8 @@ const filterCssImport = (url, ...args) => {

   return true;
 };

-// in case lightningcss fails to load, fall back to esbuild for css minify
-let LightningCssMinifyPlugin;
-try {
-  ({LightningCssMinifyPlugin} = await import('lightningcss-loader'));
-} catch {}
-
 /** @type {import("webpack").Configuration} */
 export default {
   mode: isProduction ? 'production' : 'development',
   entry: {
@@ -105,14 +99,11 @@ export default {
     minimizer: [
       new EsbuildPlugin({
         target: 'es2020',
         minify: true,
-        css: !LightningCssMinifyPlugin,
+        css: true,
         legalComments: 'none',
       }),
-      LightningCssMinifyPlugin && new LightningCssMinifyPlugin({
-        sourceMap: sourceMaps === 'true',
-      }),
     ],
     splitChunks: {
       chunks: 'async',
       name: (_, chunks) => chunks.map((item) => item.name).join('-'),

Webpack build passed (no errors).

silverwind added a commit to silverwind/gitea that referenced this issue Feb 6, 2024
Remove lightningcss and minify with esbuild again. The size of CSS will
slightly increase, but I think it's worth it to allow building gitea in
more cases like the one in the linked issue. We can reconsider once
lightningcss becomes more stable.

Fixes: go-gitea#29058
@silverwind
Copy link
Member

silverwind commented Feb 6, 2024

#29070 will fix it by removing lightningcss. We can reconsider once it becomes more stable.

wxiaoguang pushed a commit that referenced this issue Feb 7, 2024
Remove lightningcss and minify with esbuild again. The size of output
CSS will increase by around 1.4%, but I think it's worth it to allow
building gitea in more cases like the one in the linked issue. We can
reconsider once lightningcss becomes more stable.

Fixes: #29058
DennisRasey pushed a commit to DennisRasey/forgejo that referenced this issue Feb 10, 2024
Remove lightningcss and minify with esbuild again. The size of output
CSS will increase by around 1.4%, but I think it's worth it to allow
building gitea in more cases like the one in the linked issue. We can
reconsider once lightningcss becomes more stable.

Fixes: go-gitea/gitea#29058
(cherry picked from commit 5849d4f)
silverwind added a commit to silverwind/gitea that referenced this issue Feb 20, 2024
Remove lightningcss and minify with esbuild again. The size of output
CSS will increase by around 1.4%, but I think it's worth it to allow
building gitea in more cases like the one in the linked issue. We can
reconsider once lightningcss becomes more stable.

Fixes: go-gitea#29058
Copy link

Automatically locked because of our CONTRIBUTING guidelines

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/bug type/upstream This is an issue in one of Gitea's dependencies and should be reported there
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants