Migrating mastodon to Debian 11 Bullseye: fixing the segfault

In trying to upgrade a Raspberry Pi 4 from Debian 10 Buster to Debian 11 Bullseye, I made some mistakes, and basically shot my installation to pieces.

It ran, but I had absolutely no faith in it surviving a reboot.

Now that I have a working image for the Debian 11 Bullseye- based 64 bit “lite” Raspberry Pi OS, I was keen to move mastodon across to the new machine.

I’ve migrated mastodon before, and it was pretty painless: a new installation, a database dump and restore, and moving some system files.

The official mastodon migration instructions are reasonably good, if a bit confusing in their layout - you need to jump from basic to detailed, and then remember to go back to the basic instructions again. (I’ve made a pull request to the docs about this; let’s see.) But they do work.

Well, they did.

This time, they did not.

Fixing the segmentation fault

When I ran:

RAILS_ENV=production bundle exec rails assets:precompile

it resulted in several thousand lines of error message, with the crucial bit being:

/home/mastodon/live/vendor/bundle/ruby/2.7.0/gems/ffi-1.15.0/lib/ffi/library.rb:112: [BUG] Segmentation fault at 0x000000000005c6b0

Bugger.

Fortunately, I found that someone else had had a similar problem on Debian 11 and, even better, they had a solution.

Changing the systemd service definitions was fine, but the command it suggests you run:

LD_PRELOAD=libjemalloc.so RAILS_ENV=production bundle exec rake mastodon:setup

is for a new installation. Not a migration.

For a migration, you would normally run:

RAILS_ENV=production bundle exec rails assets:precompile
RAILS_ENV=production ./bin/tootctl feeds build

so I modified them using the same approach:

LD_PRELOAD=libjemalloc.so RAILS_ENV=production bundle exec rails assets:precompile
LD_PRELOAD=libjemalloc.so RAILS_ENV=production ./bin/tootctl feeds build

and that did the trick. The revised commands ran successfully, without segfaulting.