MbedTLS 1.0.2 failed to load on Julia 1.5.2 (solved by downgrading to MbedTLS 0.7.0)

I had an issue with installing a few packages that ultimately depended on MbedTLS (via HTTP). Adding and building MbedTLS 1.0.2 seemed to work fine, but while precompiling it raised the following error with undefined symbol: mbedtls_mutex_unlock:

julia> using MbedTLS
[ Info: Precompiling MbedTLS [739be429-bea8-5141-9913-cc70e7f3736d]
ERROR: LoadError: InitError: could not load library "/home/asher/.julia/artifacts/519367e9365948074c1fcc9f4365597f147a5ab7/lib/libmbedtls.so"
/usr/lib64/libmbedx509.so.0: undefined symbol: mbedtls_mutex_unlock
Stacktrace:
 [1] dlopen(::String, ::UInt32; throw_error::Bool) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Libdl/src/Libdl.jl:109
 [2] dlopen(::String, ::UInt32) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Libdl/src/Libdl.jl:109
 [3] __init__() at /home/asher/.julia/packages/MbedTLS_jll/qGMUr/src/wrappers/x86_64-linux-gnu.jl:74
 [4] _include_from_serialized(::String, ::Array{Any,1}) at ./loading.jl:697
 [5] _require_search_from_serialized(::Base.PkgId, ::String) at ./loading.jl:782
 [6] _require(::Base.PkgId) at ./loading.jl:1007
 [7] require(::Base.PkgId) at ./loading.jl:928
 [8] require(::Module, ::Symbol) at ./loading.jl:923
 [9] include(::Function, ::Module, ::String) at ./Base.jl:380
 [10] include(::Module, ::String) at ./Base.jl:368
 [11] top-level scope at none:2
 [12] eval at ./boot.jl:331 [inlined]
 [13] eval(::Expr) at ./client.jl:467
 [14] top-level scope at ./none:3
during initialization of module MbedTLS_jll
in expression starting at /home/asher/.julia/packages/MbedTLS/VbsaQ/src/MbedTLS.jl:3
ERROR: Failed to precompile MbedTLS [739be429-bea8-5141-9913-cc70e7f3736d] to /home/asher/.julia/compiled/v1.5/MbedTLS/bf9T0_1dM57.ji.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] compilecache(::Base.PkgId, ::String) at ./loading.jl:1305
 [3] _require(::Base.PkgId) at ./loading.jl:1030
 [4] require(::Base.PkgId) at ./loading.jl:928
 [5] require(::Module, ::Symbol) at ./loading.jl:923

Through a little trial and error, I found that manually installing MbedTLS as version 0.7.0 seemed to work out. Posting this here in case (1) anyone else is encountering this issue and (2) anyone has a good explanation for why this was happening.

Could you please provide more information about your operating system, version of Julia, and how did you install julia in your system?

The system it failed on is running Fedora 32 (64 bit), and I am using Julia 1.5.2, downloaded directly from julialang.org. MbedTLS.jl@0.7.0 is the latest version that doesn’t give me the undefined symbol error.

I’ve unsuccessfully tried replicating this on an Ubuntu 20.04 machine in the cloud, as it seemed to work fine on that machine.

What does the command

nm -D /usr/lib64/libmbedcrypto.so | grep mbedtls_mutex_unlock

return for you?

For libmbedcrypto it finds the symbol:
0000000000063070 D mbedtls_mutex_unlock

For libmbed509x and libmbedtls (both under /usr/lib64) I get:
U mbedtls_mutex_unlock

For any of the files in
$HOME/.julia/artifacts/519367e9365948074c1fcc9f4365597f147a5ab7/lib/*.so
I get no matching symbol.

I had the exact same error.

I am not an expert at all and what I did is just a temporary fix. I realized that my system libmbed* were older than the ones in my $HOME/.julia/artifacts/519367e9365948074c1fcc9f4365597f147a5ab7/lib folder.

So I removed the libmbed* from this julia folder and copied my system ones into the folder and it precompiled just fine (note that you might have a different version from libmbed* than 2.16.3):
cd $HOME/.julia/artifacts/519367e9365948074c1fcc9f4365597f147a5ab7/lib/
rm -f limbed*
cp /usr/lib/x86_64-linux-gnu/libmbedcrypto.so.2.16.3 ./libmbedcrypto.so
cp /usr/lib/x86_64-linux-gnu/libmbedtls.so.2.16.3 ./libmbedtls.so
cp /usr/lib/x86_64-linux-gnu/libmbedx509.so.2.16.3 ./libmbedx509.so

Then ] precompile worked just fine.

I just ran into a similar (same?) error at https://github.com/JuliaIO/HDF5.jl/issues/751#issue-752498568

Just in case anyone is coming across this again, I no longer encounter this problem with Julia 1.6.0