sass / sassc-ruby

Use libsass with Ruby!
MIT License
363 stars 157 forks source link

sassc-2.1.0.pre2 invalid pointer exception #128

Closed ahorek closed 5 years ago

ahorek commented 5 years ago

I have an error during sass compilation

free(): invalid pointer: 0x00007fe974a7ff00 ***

unfortunately no backtrace or hints where the problem could be.

it does happen only in combination with pg gem 1.1.4 and sassc-2.1.0.pre2 (precompiled version)

if I build sassc-2.1.0.pre2 from source, it doesn't happen sassc-2.1.0.pre2 (precompiled) + mysql gem also works fine so weird...

tried multiple ruby versions without any difference ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux] ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux] ...

the error never occurred to me with prior sassc versions, so it's definitelly related.

Any idea how to debug it further? @glebm I understand that the error message is quite useless, but I still wanted to report it before the final release.

thanks!

my env

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.9.2-10+deb8u2' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.9 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --with-arch-32=i586 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.9.2 (Debian 4.9.2-10+deb8u2)
Linux --- 4.9.133-xxxx-std-ipv6-64 #413770 SMP Mon Oct 15 08:12:05 UTC 2018 x86_64 GNU/Linux
ahorek commented 5 years ago

investigating...

variables.scss

$gap: 12px !default;
$font-size: 15px !default;
$text-beta: #ae1400 !default;

main.scss

@import "variables";

.management {
  &_indicator {
    margin-right: 4*$gap;
    position: absolute;
    display: inline-block;
    font-size: $font-size;
    color: $text-beta;
    top: 1.75*$gap;
    padding-left: .25*$gap;
  }
}

if I inline variables.scss into main.scss, it works. So it looks like any use of @import triggers the error.

ahorek commented 5 years ago

@bolandrm could you share a linux binary built on your environment with debug flags enabled? https://github.com/sass/sassc-ruby/pull/129

glebm commented 5 years ago

@ahorek The pre-built binary is built in a Docker container, so everyone should have the same environment.

To build it, simply clone the repo and run bundle exec rake gem:native. It will be in pkg/.

glebm commented 5 years ago

@ahorek You need to have Docker and VirtualBox installed for rake gem:native to work.

ahorek commented 5 years ago

ok, I'll try that

glebm commented 5 years ago

Compiled just now with the no-strip patch:

sassc-2.1.0.pre2-x86_64-linux.gem.zip

This was compiled on my Windows machine but that shouldn't matter.

ahorek commented 5 years ago

I was able to build https://github.com/sass/sassc-ruby/pull/129 according to your manual, however the error remains the same

...
I, [2019-06-12T01:09:17.692716 #2572]  INFO -- : Writing /home/gitlab-runner/test/sassctest/devel/public/assets/asset-3d857124e31be2ed5924711e99957f250e939d51e4c75df19bf6393b1a5cf204.js.gz
*** Error in `ruby /usr/local/rvm/gems/ruby-2.3.3-railsexpress/bin/rake install RAILS_ENV=production --trace': free(): invalid pointer: 0x00007f894ea69f00 ***
Aborted
glebm commented 5 years ago

Perhaps you can try debugging with valgrind?

valgrind --tool=memcheck ./your-command
glebm commented 5 years ago

http://www.valgrind.org/docs/manual/quick-start.html

ahorek commented 5 years ago

This looks suspicious:

snipet
==1985== Invalid free() / delete / delete[] / realloc()
==1985==    at 0x4C29AB1: operator delete[](void*) (vg_replace_malloc.c:651)
==1985==    by 0x1A6F5541: std::locale::_Impl::_M_install_facet(std::locale::id const*, std::locale::facet const*) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==1985==    by 0x1A6F59A2: std::locale::_Impl::_Impl(unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==1985==    by 0x1A6F6914: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==1985==    by 0x53D540F: pthread_once (pthread_once.S:103)
==1985==    by 0x1A6F6960: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==1985==    by 0x1A6F69A2: std::locale::locale() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==1985==    by 0x1A73D518: std::basic_filebuf >::basic_filebuf() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==1985==    by 0x197CE2F5: Sass::File::read_file(std::__cxx11::basic_string, std::allocator > const&) (in /usr/local/rvm/gems/ruby-head-opt/gems/sassc-2.1.0.pre2-x86_64-linux/lib/sassc/libsass.so)
==1985==    by 0x1989DA5B: Sass::Context::load_import(Sass::Importer const&, Sass::ParserState) (in /usr/local/rvm/gems/ruby-head-opt/gems/sassc-2.1.0.pre2-x86_64-linux/lib/sassc/libsass.so)
==1985==    by 0x1989E048: Sass::Context::import_url(Sass::Import*, std::__cxx11::basic_string, std::allocator >, std::__cxx11::basic_string, std::allocator > const&) (in /usr/local/rvm/gems/ruby-head-opt/gems/sassc-2.1.0.pre2-x86_64-linux/lib/sassc/libsass.so)
==1985==    by 0x1989F769: Sass::Context::call_loader(std::__cxx11::basic_string, std::allocator > const&, char const*, Sass::ParserState&, Sass::Import*, std::vector >, bool) (in /usr/local/rvm/gems/ruby-head-opt/gems/sassc-2.1.0.pre2-x86_64-linux/lib/sassc/libsass.so)
==1985==  Address 0x1a98ef00 is in the BSS segment of /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20

I'll share a full log soon.

glebm commented 5 years ago

I found a thread on gcchelp about this that seems somewhat related: https://www.spinics.net/lists/gcchelp/msg46851.html

glebm commented 5 years ago

From the gcchelp thread it looks like there is some kind of compatibility issue (bug) with GCC 4/5 and the locale header.

Can you please try with this patch:

https://github.com/glebm/libsass/commit/3b5190a62bb17f0cef5e0e837e37603623740fb2

It avoids initializing locales by using the C API to read files instead of the C++ one.

ahorek commented 5 years ago

full report https://github.com/ahorek/sassc-ruby/blob/report/valout.txt

ahorek commented 5 years ago

thank you @glebm !

I can confirm the patch https://github.com/glebm/libsass/commit/3b5190a62bb17f0cef5e0e837e37603623740fb2 fixes the problem. All tests passed.

do we need a new libsass release?

glebm commented 5 years ago

do we need a new libsass release?

Maybe not, sent #130 to build from the right commit.

bolandrm commented 5 years ago

@ahorek 2.1.0.pre3 released containing this fix

deepj commented 5 years ago

Unfortunately, I'm getting the same issue with the pointer. sassc 2.1.0 on CentOS 7 with ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]. pg 1.1.4 is used as well.