herokuld-preloadjemallocquotaguard

LD_PRELOAD not working on Heroku + jemalloc + quotaguard


TL;DR: update your bin/qgtunnel.


I've recently noticed an increase in my web dyno's memory usage. After digging a bit, I could see that the LD_PRELOAD variable that should be set with heroku-buildpack-jemalloc was not set correctly. I used a tiny script (bin/show_preload) that helped me debug that and trace which program was overriding LD_PRELOAD.

#!/usr/bin/env bash

echo "buildpack=foo preload='$LD_PRELOAD' at=start-app cmd='$@'"
$@

I introduced that in our Procfile:

web: bin/show_preload bin/qgtunnel bin/show_preload bin/start-nginx bin/show_preload bin/start-pgbouncer bin/show_preload bundle exec puma -C config/puma.rb

And when lauching on heroku I can see that bin/qgtunnel overrides our LD_PRELOAD configuration.

I created a tiny helper for the time being which makes sure I keep original value as well as what is added by bin/qgtunnel:

#!/usr/bin/env bash

after_qgtunnel_script=$(mktemp)
echo <<-BASH > $after_qgtunnel_script
    # Retrieve previous LD_PRELOAD value
    export LD_PRELOAD="\$LD_PRELOAD $LD_PRELOAD"

    # Clean after usage
    rm $after_qgtunnel_script

    # Start following commands
    $@
BASH

chmod +x $after_qgtunnel_script

bin/qgtunnel $after_qgtunnel_script $@

If you ever need this script use it in place of bin/qgtunnel


Solution

  • After reaching out to Quotaguard, they patched the qgtunnel binary and there is no error anymore:

    curl https://quotaguard.s3.amazonaws.com/qgtunnel-2.4.1.tar.gz | tar xz
    git add bin/qgtunnel vendor/nss_wrapper/libnss_wrapper.so
    git commit -m "Update qgtunnel to fix LD_PRELOAD"
    

    NOTE: new versions may occur since that one, see the related documentation