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

Segmentation fault on "RAILS_ENV=production assets:precompile" #122

Open
icr4 opened this issue May 3, 2019 · 46 comments
Open

Segmentation fault on "RAILS_ENV=production assets:precompile" #122

icr4 opened this issue May 3, 2019 · 46 comments

Comments

@icr4
Copy link

icr4 commented May 3, 2019

/home/icra/.gem/ruby/2.5.0/gems/sassc-2.0.1/lib/sassc/engine.rb:42: [BUG] Segmentation fault at 0x0000000000000000
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]

-- Control frame information -----------------------------------------------
c:0065 p:---- s:0385 e:000384 CFUNC :compile_data_context
c:0064 p:0298 s:0380 e:000379 METHOD /home/icra/.gem/ruby/2.5.0/gems/sassc-2.0.1/lib/sassc/engine.rb:42

--- EDIT ----
Excluding CSS files one by one i discovered the problem is my "style.css", but it has no errors, and the stacktrace is not appointing it so i can understand the error.
The CSS compiles well on another project using same version of sass-c. I tried creating a new rails app and it still crashes.

@icr4 icr4 changed the title Segmentation fault on assets:precompile Segmentation fault on "RAILS_ENV=production assets:precompile" May 3, 2019
@bolandrm
Copy link
Member

bolandrm commented May 3, 2019

Hi, could you make style.css available so that someone might try to reproduce and fix the issue?

@ahorek
Copy link

ahorek commented May 4, 2019

Hi, I have the same problem.

test.css

/*
 *= require_self
*/

div {
    background: image-url('arrow.gif');
}

but if I put that into an .scss file it works fine, that could be a workaround for you.

@icr4
Copy link
Author

icr4 commented May 6, 2019

Hi, I have the same problem.

test.css

/*
 *= require_self
*/

div {
    background: image-url('arrow.gif');
}

but if I put that into an .scss file it works fine, that could be a workaround for you.

They already are .scss, i solved switching back to 'sass-rails' temporarily hoping the problem will get fixed soon.

@halo
Copy link

halo commented Jun 20, 2019

I encounter this with the follwoing .sass file (not.scss)

@font-face
  // If i comment out the following line, there is no segfault
  src: asset-url('some_custom_font.woff') format('woff')

It reminds me of this issue that caused a segfault whenever a pipeline helper was called.

  • sprockets 4.0.0.beta9
  • rails 6.0.0.rc1
  • Ruby 2.6.1
  • sassc 2.0.1
  • sassc-rails 2.1.2

EDIT This appeared after a bundle update, so I tried to find the culprit by upgrading the mentioned gems one by one. After I did that, the segfault now disappeared. Weird. But I'm happy now ;)

EDIT2 I still have this problem, but intermittently. The problem disappears when I make modifications to SASS in another file, at some other place in the stylesheet assembly. If I make more changes, the problem is back. If I change something, it's gone again. I have not been able to reproduce it reliably though.

@ozgg
Copy link

ozgg commented Oct 10, 2019

I have this problem too, and it's hard to reproduce it. It happens unexpectedly with different projects and disappears, when I update any file used (just add blank line to any scss file, for example). And it doesn't appear again even after I remove that blank line.

@jkwuc89
Copy link

jkwuc89 commented Oct 14, 2019

I am getting this segmentation fault consistently within the Rails project I am working on. It results from running: `NODE_ENV=production RAILS_ENV=production bundle exec dotenv 'bin/rails assets:precompile'. The dump/stack trace is attached.

I am using:

  • Ruby 2.5.5
  • Rails 6.0.0
  • macOS Catalina
  • Xcode 11 with command line tools installed

sassc_crash_stack_trace.txt

@kernow
Copy link

kernow commented Oct 19, 2019

I'm seeing the same issue when precompiling assets on deployment.

  • sprockets 4.0.0
  • rails 5.2.3
  • Ruby 2.5.5
  • sassc 2.2.1
  • sassc-rails 2.1.2

I only saw this issue after upgrading from sprockets 3.7.2 to 4.0.0. Revert back to sprockets 3.7.2 and the issue goes away.

@adesurirey
Copy link

Same issue running RAILS_ENV=production bundle exec rake assets:precompile with Travis CI.

  • rails 6.0.1
  • sprockets 4.0.0
  • Ruby 2.6.5
  • sassc 2.2.1
  • sassc-rails 2.1.2

@martinezcoder
Copy link

I had the same issue upgrading to sass-rails 6.0.0 and finally I fixed it using sprockets 4.

  • ruby 2.6.5
  • rails 6.0.1
  • sass-rails 6.0.0
  • sprockets 4.0.0

There is something that is told indirectly in the sprockets upgrading readme:

# In your Rails configuration, prior to Sprockets 4
config.assets.precompile += ["marketing.css"]

This kind of configuration is necessary only if you are using a prior version of Sprockets 4. The upgrading documentation is not warning about the need to remove those kind of lines, but at least in my case, removing them and adding that dependencies in the manifest.js file has fixed the issue.

This post was very useful to understand the changes between versions.

@epipheus
Copy link

epipheus commented Dec 1, 2019

I've tried with with every permutation I can think of sassc and sass-rails with no love. using manifest.js already. works in dev, no clue why not in production. Attached the vomit from the crash.

precompile.out.txt

@epipheus
Copy link

epipheus commented Dec 1, 2019

Also, just a note, this was all working on rails 6.0.1 with manifests and gemified assets so I'm sure they aren't the cause, which really make this perplexing for me. sassc I think is the only thing that changed. For some stupid reason I removed the version from my Gemfile. Looking through git for where it went wrong.

@epipheus
Copy link

epipheus commented Dec 2, 2019

Not getting a useful error msg and instead getting a segfault can be quite annoying. Is anyone from sassc-rails going to actually comment? OP filed in May, it's almost Dec. Is there anything you need from us to shed more light? How can we get help?

@ozgg
Copy link

ozgg commented Dec 2, 2019

@epipheus I think the problem is that nobody can reliably reproduce this error, so comments from the team won't help either. The only information everyone has is: sometimes it unexpectedly crashes and the next consequent time it works.

@epipheus
Copy link

epipheus commented Dec 2, 2019

Can I ask this? what's the difference between doing rails assets:precompile in dev vs prod mode? Why would the outcome be different in those environments? Maybe if we understand that we can sort it out.

@ozgg
Copy link

ozgg commented Dec 2, 2019

I get crashes for both development and production environments. The only difference is that dev crashes until I change any scss file, but for prod it crashes only once.

@epipheus
Copy link

epipheus commented Dec 2, 2019

hmm. i haven't flipped around to it working yet for me in production. Dev, no problem, as all. Even precompiles in dev without a hitch. which is super odd. OK, can I ask this, before we used sassc there are a pure ruby one right? took forever, but it existed I thought. How can we revert to that one? We should at least be able to fully trace right?

@epipheus
Copy link

epipheus commented Dec 2, 2019

I read somewhere there used to be a problem with concurrency for precompilation, the workaround of disabling concurrency didn't work for me and besides it's supposedly rolled into previous versions. I also went through and started taking out asset url helpers from my assets instead using scss variable and referencing from /assets. have asset references working in dev with that but still no precompilation love. I basically can't push needed changes to production because the deploy fails at asset compilation, which sucks. Anyone have any ideas?

@martinezcoder
Copy link

@epipheus

  • What version of sprockets are you using? I guess you are using sprockets version 4

  • Did you remove the lines using Rails.application.config.assets.precompile += [...] in your config/initializers/assets.rb?

  • Are you adding your JS and CSS to app/assets/config/manifest.js following this guide?

If after doing all this is still not working, you can force your project to use sprockets version 3.7.2 and it should work.

@epipheus
Copy link

epipheus commented Dec 3, 2019

Yes, using 4.0.0 and I moved to manifest.js when I upgraded to rails 6.0.1. I will try sprockets 3.7.2. Manifests work in sprockets 3?

@epipheus
Copy link

epipheus commented Dec 3, 2019

Tried 3.7.2 and it partially precompiled, most progress yet, but still crashed; do you know if there is a combination of sprockets with sprockets-rails and sassc and sassc-rails version voodoo that works in particular?

@epipheus
Copy link

epipheus commented Dec 3, 2019

I don't know if this is helpful, but I can tell you how I tracked down my problem. Maybe it will help you, because I'm my case it was a ridiculous needle in the haystack. I used gemified assets on my large projects so it was particularly hard to track down especially since other projects used the same pack of assets. I went old-school and forked sassc-ruby and printed debug messages before the offending line.

Looking at my own segfault and others’, the offending line is almost always this line in the sassc-ruby engine

I went old-school and printed a few debug messages before the offending line

status = Native.compile_data_context(data_context)

As for instance variable, in my case:

  • filename is almost always empty
  • context and data_context, native_options all hold FFI pointers with the same address
  • options almost always just has {style: :compressed} in it

Sadly the only useful instance variable seems to be template which holds the contents of the asset (css or scsss). Luckily enough for me it was a vendor css file with it’s name at the top. I went to that file exactly to see what was wrong and turns out that the file name was blah.css but it was edited to have asset_url helpers in it. Literally just renaming the file to blah.scss meant all of my assets compiled. And not just for sprockets 3.7.2 but for 4.0.0 as well.

I don’t have much experience binding C and Ruby but seems to me that we need to wrap sassc-ruby’s line:

status = Native.compile_data_context(data_context)

with something that can fail gracefully (?).

Also why aren’t file names non-empty/present? That would help people tremendously to have a mode like rails assets:precompile --verbose that simply prints the current asset being processed so we have a place to look for issues.

Lastly, given css is a subset of scss, would it be a bad idea to import all css as scss/sass, expecially if config.assets.css_compressor = :sass ?

@martinezcoder
Copy link

martinezcoder commented Dec 3, 2019

You went much deeply with the error than me... AFAIK, although the segmentation fault occurs in sassc-rails, I suspect that the problem starts earlier in sprockets and some kind of corner case of incompatibility with this sassc. If you see the file you shared ( precompile.out.txt ) before starting with sassc it was on sprockets-4.0.0/lib/sprockets/sass_compressor.rb:30 and sprockets-4.0.0/lib/sprockets/processor_utils.rb:84.

I am sorry to not having a technical explanation about the problem, but I could fix the problem with two different ways:

  • Using a previous version of sprockets. In my case it worked fine with 3.7.2
    or
  • Removing all the Rails.application.config.assets.precompile += [...] and doing the work in the manifest.js. The problem in our code was that we had one Rails.application.config.assets.precompile += [...] that was not inserted in the manifest.js. So we removed the Rails.application.config.assets.precompile += [...] and inserted this JS in the manifest. And it worked for us.

For us, both options worked, so we decided to go with the second one because it was using sprockets 4.

But the easiest way to fix this issue is to downgrade to sprockets 3.7.2.

@epipheus
Copy link

epipheus commented Dec 3, 2019

Ahh, well I guess my segfault location changed. downgrading to 3.7.2 partially worked for me but it crash at like 42 of the sassc-ruby engine, which seems to also be the location of the OP's (@icra-zz) segfault as well.

/home/icra/.gem/ruby/2.5.0/gems/sassc-2.0.1/lib/sassc/engine.rb:42: [BUG] Segmentation fault at 0x0000000000000000
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
-- Control frame information -----------------------------------------------
c:0065 p:---- s:0385 e:000384 CFUNC :compile_data_context
> c:0064 p:0298 s:0380 e:000379 METHOD /home/icra/.gem/ruby/2.5.0/gems/sassc-2.0.1/lib/sassc/engine.rb:42

I think my point here is that there probably is a way to eliminate a fair percentage of these with simply a message stating which asset we're on in the process when it fails. There are probably only a few choke points, with compilation likely being the major one. Is there not a way to try a ffi C function?

And btw, finding this needle in the haystack meant being able to use the latest version of all the component without a hitch. And I moderately stressed precompilation to see if it would appear again, it hasn't. It might not be sprocket's fault at all; it's possible, perhaps it's the joints and not the meat, so to speak.

I would bet, many of the segfaults die at line 42. of those that fall there a large percent probably could be completely eliminated by importing css as scss (certainly eliminates having helpers blow things up). I don't know about you guys but my large apps have a ton of assets. finding that needle is a real pain without basic information.

@ozgg
Copy link

ozgg commented Dec 3, 2019

I think it's not directly connected with the contents of assets. If I'll find time, I'll try to reproduce this with almost empty scss like body { font-size: 16px; }. In the very beginning of this thread there is an example with a very simple file.

@epipheus
Copy link

epipheus commented Dec 3, 2019

thanks.

@epipheus
Copy link

epipheus commented Dec 3, 2019

No wait dude, this is exactly what I described.

  • Failure at sassc line 42 not sassc-rails

  • the tiny code sample uses an asset url helper image-url which is not OK for css but is OK for scss

  • instead of a graceful message it segfaults.

This is exactly what's I've just described. Changing it to scss is what makes it ok. I love to blame sprockets too, but I just don't think it is.

Hi, I have the same problem.
test.css

/*
 *= require_self
*/

div {
    background: image-url('arrow.gif');
}

but if I put that into an .scss file it works fine, that could be a workaround for you.

They already are .scss, i solved switching back to 'sass-rails' temporarily hoping the problem will get fixed soon.

@martinezcoder
Copy link

Yep, I commented this issue some months ago in this thread #122 (comment). This possibility was declined, but anyway, in my case, it worked after amending the assets.precompile line in favour of manifest.js.

Obsiye added a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Feb 13, 2020
This fixes a segmentation error in circle ci after upgrading to rails 6
this is when the docker file runs assets:precompile
sass/sassc-rails#122
The error can be found above
Obsiye added a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Feb 13, 2020
This fixes a segmentation error in circle ci after upgrading to rails 6
this is when the docker file runs assets:precompile
sass/sassc-rails#122
The error can be found above
Obsiye added a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Feb 14, 2020
Update Rails to version 6.0.2

Downgrage sprockets to 3.7.2. This fixes a segmentation error in circle ci after upgrading to rails 6
this is when the docker file runs assets:precompile
sass/sassc-rails#122
Obsiye added a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Feb 14, 2020
Update Rails to version 6.0.2

Downgrage sprockets to 3.7.2. This fixes a segmentation error in circle ci after upgrading to rails 6
this is when the docker file runs assets:precompile
sass/sassc-rails#122
Obsiye added a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Feb 18, 2020
Update Rails to version 6.0.2

Downgrage sprockets to 3.7.2. This fixes a segmentation error in circle ci after upgrading to rails 6
this is when the docker file runs assets:precompile
sass/sassc-rails#122
Obsiye added a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Feb 21, 2020
Update Rails to version 6.0.2

Downgrage sprockets to 3.7.2. This fixes a segmentation error in circle ci after upgrading to rails 6
this is when the docker file runs assets:precompile
sass/sassc-rails#122
Obsiye added a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Feb 21, 2020
Update Rails to version 6.0.2

Downgrage sprockets to 3.7.2. This fixes a segmentation error in circle ci after upgrading to rails 6
this is when the docker file runs assets:precompile
sass/sassc-rails#122
@jnettome
Copy link

jnettome commented Apr 1, 2020

After adding (and downgrading at same time) gem 'sprockets', '3.7.2' to my Gemfile, on my Rails 6 app, it works again. 👊

@flanger001
Copy link

flanger001 commented Apr 7, 2020

I'm getting this in a Rails 5.2 app with sprockets 4.0.0 as well, but only on Travis CI. It works fine on macOS.

I had this issue but then realized why I was getting it - I forgot to remove my assets from Rails.application.config.assets.precompile. They were doubled up there and in app/assets/config/manifest.js. Once I removed them from the precompile array, it worked for me. My issue was similar to sass/sassc-ruby#133

@manoelneto
Copy link

Same as @jnettome

After adding (and downgrading at same time) gem 'sprockets', '3.7.2' to my Gemfile, on my Rails 6 app, it works again. 👊

@markkiky
Copy link

markkiky commented Oct 7, 2020

Had a similar problem in production mode but a working development mode.
I worked around this by using yui for css compile and uglifier for js compile

  1. Gemfile
group :production do 
  # Compile javascripts and css in production
  gem 'uglifier', '~> 4.2'
  gem 'yui-compressor', '~> 0.12.0'
end
  1. production.rb
    config.assets.css_compressor = :yui
    config.assets.js_compressor = Uglifier.new(harmony: true)

Hope this helps

@kihara-ori
Copy link

My assets files were a mixture of files with the .css extension.
I changed them all to the .sass extension and the error was resolved.

@Jetinho
Copy link

Jetinho commented May 2, 2021

gem 'sprockets', '3.7.2'

After adding (and downgrading at same time) gem 'sprockets', '3.7.2' to my Gemfile, on my Rails 6 app, it works again. fist_oncoming

Hello, I'm facing the same issue and this workaround also solved the problem on my Rails 6 app.

However I can't help thinking this is not a "clean" fix, since we downgrade on purpose a relatively important dependency of our app.

I have not enough knowledge / experience to judge this, so if anyone has a piece of advice about that I'd be glad !

@jnettome, @manoelneto ?

shaun-technovation added a commit to Iridescent-CM/technovation-app that referenced this issue Aug 5, 2021
Various suggestions to downgrade sprockets to fix a segfault crash:

sass/sassc-ruby#207
sass/sassc-rails#122
rails/sprockets#633

We'll see if that fixes it for us.

Refs: #2872
shaun-technovation added a commit to Iridescent-CM/technovation-app that referenced this issue Aug 6, 2021
Various suggestions to downgrade sprockets to fix a segfault crash:

sass/sassc-ruby#207
sass/sassc-rails#122
rails/sprockets#633

We'll see if that fixes it for us.

Refs: #2872
koetsier added a commit to GovWifi/govwifi-admin that referenced this issue Sep 13, 2021
We had this pinned to version 3.7.2 because of a segmentation
fault that occurred when upgrading to 4.0+

After investigation it seems that Sprockets now uses the manifest.js
file to compile assets instead of the assets.rb file.

See: sass/sassc-rails#122 and
https://github.com/rails/sprockets/blob/master/UPGRADING.md#manifestjs

This commit upgrades Sprockets and now uses the manifest.js file
to precompile assets which ensures the segmentation fault no
longer occurs.
koetsier added a commit to GovWifi/govwifi-admin that referenced this issue Sep 13, 2021
We had this pinned to version 3.7.2 because of a segmentation
fault that occurred when upgrading to 4.0+

After investigation it seems that Sprockets now uses the manifest.js
file to compile assets instead of the assets.rb file.

See: sass/sassc-rails#122 and
https://github.com/rails/sprockets/blob/master/UPGRADING.md#manifestjs

This commit upgrades Sprockets and now uses the manifest.js file
to precompile assets which ensures the segmentation fault no
longer occurs.
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

No branches or pull requests