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

"symbol not found" on alpine 3.19 #434

Closed
rickselby opened this issue Dec 12, 2023 · 12 comments · Fixed by #442
Closed

"symbol not found" on alpine 3.19 #434

rickselby opened this issue Dec 12, 2023 · 12 comments · Fixed by #442

Comments

@rickselby
Copy link

rickselby commented Dec 12, 2023

TL;DR from the maintainers -- read me first!

You can work around this issue in three ways:

  1. upgrade to sqlite3 >= v2.0.0
  2. pin to alpine 3.18
  3. compile the gem from source, see INSTALLATION.md

(The original bug description follows)


On the latest ruby image with alpine 3.19, I can install sqlite3 ruby gem, but it emits "symbol not found" errors at runtime.

This is a quick test on alpine 3.18:

$ docker run --rm -it ruby:3.2.2-alpine3.18 /bin/sh
/ # gem install sqlite3
Fetching sqlite3-1.6.9-x86_64-linux.gem
Successfully installed sqlite3-1.6.9-x86_64-linux
1 gem installed

A new release of RubyGems is available: 3.4.10 → 3.4.22!
Run `gem update --system 3.4.22` to update your installation.

/ # ruby -rsqlite3 -e 'puts SQLite3::SQLITE_LOADED_VERSION'
4.44.2
/ # 

And here's the same on 3.19:

$ docker run --rm -it ruby:3.2.2-alpine3.19 /bin/sh
/ # gem install sqlite3
Fetching sqlite3-1.6.9-x86_64-linux.gem
Successfully installed sqlite3-1.6.9-x86_64-linux
1 gem installed

A new release of RubyGems is available: 3.4.10 → 3.4.22!
Run `gem update --system 3.4.22` to update your installation.

/ # ruby -rsqlite3 -e 'puts SQLite3::SQLITE_LOADED_VERSION'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- sqlite3/sqlite3_native (LoadError)
	from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /usr/local/bundle/gems/sqlite3-1.6.9-x86_64-linux/lib/sqlite3.rb:6:in `rescue in <top (required)>'
	from /usr/local/bundle/gems/sqlite3-1.6.9-x86_64-linux/lib/sqlite3.rb:2:in `<top (required)>'
	from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:159:in `require'
	from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:159:in `rescue in require'
	from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:39:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require': Error relocating /usr/local/bundle/gems/sqlite3-1.6.9-x86_64-linux/lib/sqlite3/3.2/sqlite3_native.so: posix_fallocate64: symbol not found - /usr/local/bundle/gems/sqlite3-1.6.9-x86_64-linux/lib/sqlite3/3.2/sqlite3_native.so (LoadError)
	from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /usr/local/bundle/gems/sqlite3-1.6.9-x86_64-linux/lib/sqlite3.rb:4:in `<top (required)>'
	from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:159:in `require'
	from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:159:in `rescue in require'
	from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:39:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- sqlite3 (LoadError)
	from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
/ # 

I'm not sure if this is the gem or the docker image causing the issue here.

@flavorjones
Copy link
Member

Similar report just came in #435, too.

I believe something changed in the alpine image, since we test alpine in the CI pipeline and it passed last week, but started failing yesterday with the new image

Will investigate. In the meantime, a workaround is to use ruby:3-alpine3.18

@pdfrod
Copy link

pdfrod commented Dec 12, 2023

I copied /lib/ld-musl-x86_64.so.1 from ruby:3-alpine3.18 Docker image and that seems to fix the problem, so it would appear that the problem is related to some change in Musl libc or how Musl is compiled.

By looking the exported symbols from the library (e.g., readelf -Ws --dyn-syms /lib/ld-musl-x86_64.so.1 | grep posix_fallocate64) I've confirmed that the symbol posix_fallocate64 is present in the previous version but missing in the new version. I'm not sure yet if this was intended or if it was an oversight. I'll try to dig more.

@flavorjones flavorjones changed the title Cannot install on alpine 3.19 "symbol not found" on alpine 3.19 Dec 12, 2023
@flavorjones
Copy link
Member

Just a note: the symbol missing for the user in #435 is fcntl64, where the one reported missing in this issue is posix_fallocate64.

@flavorjones flavorjones pinned this issue Dec 12, 2023
@pdfrod
Copy link

pdfrod commented Dec 13, 2023

OK, it seems this was an intentional breaking change in Musl 1.24:

On the API level, the legacy "LFS64" ("large file support") interfaces, which were provided by macros remapping them to their standard names (#define stat64 stat and similar) have been deprecated and are no longer provided under the _GNU_SOURCE feature profile, only under explicit _LARGEFILE64_SOURCE. The latter will also be removed in a future version. Builds broken by this change can be fixed short-term by adding -D_LARGEFILE64_SOURCE to CFLAGS, but should be fixed to use the standard interfaces.

So if I understood correctly, functions with the 64 suffix were dropped and the correct fix is to use the unsuffixed versions instead.

Here are examples of other projects that were also affected by this:

@flavorjones
Copy link
Member

@pdfrod Thank you so much for doing this research! I should have time tomorrow to investigate if I can work around this in the native (precompiled) gems.

@flavorjones
Copy link
Member

I'm not sure there's a fix for this other than for rake-compiler-dock to support generating native musl-specific gems. Upstream issue is rake-compiler/rake-compiler-dock#75

@rubys
Copy link

rubys commented Dec 14, 2023

Workarounds:

  • bundle config force_ruby_platform true
  • sed -i '/sqlite3/ s/$/, force_ruby_platform: true/' Gemfile

(2023-12-19 - Maintainer's note: these workarounds will compile the gem at installation time on the target machine, and are fully explained in INSTALLATION.md)

@rickselby
Copy link
Author

Thanks for looking into this; I did wonder if it was upstream.

I'll pin to alpine-3.18 for now.

flavorjones added a commit that referenced this issue Dec 19, 2023
because 3.19 fails due to #434. While I work on better musl support,
this makes CI a bit more meaningful.
flavorjones added a commit that referenced this issue Dec 19, 2023
@flavorjones
Copy link
Member

I've updated the issue description with a TLDR summary of the workarounds.

flavorjones added a commit that referenced this issue Dec 19, 2023
because 3.19 fails due to #434. While I work on better musl support,
this makes CI a bit more meaningful.
flavorjones added a commit that referenced this issue Dec 19, 2023
because 3.19 fails due to #434. While I work on better musl support,
this makes CI a bit more meaningful.
flavorjones added a commit that referenced this issue Dec 19, 2023
flavorjones added a commit that referenced this issue Dec 19, 2023
flavorjones added a commit to rake-compiler/rake-compiler-dock that referenced this issue Dec 19, 2023
flavorjones added a commit to rake-compiler/rake-compiler-dock that referenced this issue Dec 28, 2023
@kmcphillips
Copy link

Confirm a breaking change in the Alpine image. I redeployed the same app with no change to the Gemfile or Dockerfile and now receive this error:

[info] /usr/local/bundle/gems/sqlite3-1.7.0-x86_64-linux/lib/sqlite3.rb:6:in `require': cannot load such file -- sqlite3/sqlite3_native (LoadError)
[info] Did you mean? sqlite3/3.3/sqlite3_native
[info] sqlite3/3.2/sqlite3_native
[info] sqlite3/3.1/sqlite3_native
[info] sqlite3/3.0/sqlite3_native
[info] from /usr/local/bundle/gems/sqlite3-1.7.0-x86_64-linux/lib/sqlite3.rb:6:in `rescue in <top (required)>'
...

And that this diff got my deploy working again:

--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM ruby:3.2.2-alpine AS base
+FROM ruby:3.2.2-alpine3.18 AS base

( 👋 👋 Hi Mike)

flavorjones added a commit to rake-compiler/rake-compiler-dock that referenced this issue Jan 2, 2024
kmcphillips added a commit to kmcphillips/digital_stress that referenced this issue Jan 3, 2024
jk779 added a commit to jk779/csp_reporter that referenced this issue Jan 22, 2024
jk779 added a commit to jk779/csp_reporter that referenced this issue Jan 22, 2024
@flavorjones
Copy link
Member

Please follow #442 for the fix-in-progess for this issue.

flavorjones added a commit that referenced this issue Jan 24, 2024
flavorjones added a commit that referenced this issue Jan 25, 2024
flavorjones added a commit that referenced this issue Feb 7, 2024
bougyman added a commit to rubyists/linear-cli that referenced this issue Feb 9, 2024
flavorjones added a commit that referenced this issue Feb 25, 2024
flavorjones added a commit that referenced this issue Mar 24, 2024
flavorjones added a commit that referenced this issue Mar 24, 2024
Quintasan added a commit to Quintasan/przypominacz-bot that referenced this issue Mar 28, 2024
tim-kuntz added a commit to tim-kuntz/rails_panel that referenced this issue Apr 4, 2024
There were 2 issues that were breaking the build and tests.

1. Updating Ruby Gems itself without specifying a version causes it to update to the latest version which requires Ruby 3. Instead, we specify the latest version compatible with the installed Ruby.

Compatibility versions found here:
https://rubygems.org/api/v1/versions/rubygems-update.json

2. All builds were having issues with missing shared libraries. In the case of the Ruby 2.6 images it was nokogiri and for the Ruby 3.0 image it was sqlite3. A common fix for all the builds was to configure Bundler to consider the platform during dependency resolution.

More information found here:
https://bundler.io/v1.14/whats_new.html
sparklemotion/sqlite3-ruby#434
github/pages-gem#839 - alt. fix for Ruby 2.6
flavorjones added a commit that referenced this issue Apr 15, 2024
@flavorjones
Copy link
Member

Should be fixed in v2.0.0 with the linux-musl native gem.

rubys added a commit to fly-apps/dockerfile-rails that referenced this issue Apr 17, 2024
lucas42 added a commit to lucas42/lucos_schedule_tracker that referenced this issue Apr 21, 2024
Problems with `sqlite3-ruby` and 3.19 have been fixed in version 2.0.0 of the gem, so upgrade that too.  See sparklemotion/sqlite3-ruby#434
dbackeus added a commit to reclaim-the-stack/talos-manager that referenced this issue Jun 18, 2024
sqlite3 gem version 2.x fixes this but 1.x is required by Rails.

Reference: sparklemotion/sqlite3-ruby#434
dbackeus added a commit to reclaim-the-stack/talos-manager that referenced this issue Jun 18, 2024
sqlite3 gem version 2.x fixes this but 1.x is required by Rails.

Reference: sparklemotion/sqlite3-ruby#434
dbackeus added a commit to reclaim-the-stack/talos-manager that referenced this issue Jun 18, 2024
sqlite3 gem version 2.x fixes this but 1.x is required by Rails.

Reference: sparklemotion/sqlite3-ruby#434
dbackeus added a commit to reclaim-the-stack/talos-manager that referenced this issue Jun 18, 2024
sqlite3 gem version 2.x fixes this but 1.x is required by Rails.

Reference: sparklemotion/sqlite3-ruby#434
dbackeus added a commit to reclaim-the-stack/talos-manager that referenced this issue Jun 29, 2024
* Add support for SQLite

* Use async actioncable adapter in sqlite mode

* Downgrade sqlite3 gem for Rails compatibility

* Use slim docker image to fix sqlite3 issue

sqlite3 gem version 2.x fixes this but 1.x is required by Rails.

Reference: sparklemotion/sqlite3-ruby#434

* Use LOWER + LIKE instead of ILIKE since SQLite doesn't have ILIKE
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 a pull request may close this issue.

5 participants