JuliaDatabases / LibPQ.jl

A Julia wrapper for libpq
MIT License
217 stars 51 forks source link

LibPQ.jl crashed on Alpine 3.20 with the latest 1.18.0 version, resulting in a segmentation fault error. #302

Open chamikabm opened 3 weeks ago

chamikabm commented 3 weeks ago

Part of the docker file:

FROM julia:1.6-alpine3.20

# Try to boost precompilation speed
ENV JULIA_NUM_THREADS=4

# Define versions for libraries as environment variables for CVEs
ENV LIBCRYPTO3_VERSION="3.3.1-r3"
ENV LIBSSL3_VERSION="3.3.1-r3"
ENV BUSYBOX_VERSION="1.36.1-r29"
ENV SSL_CLIENT_VERSION="1.36.1-r29"

WORKDIR /app
COPY . .
RUN rm Manifest.toml -f

RUN apk add --update --no-cache \
    gcc \
    libpq \
    musl-dev \
    libssl3=$LIBSSL3_VERSION \
    libcrypto3=$LIBCRYPTO3_VERSION \
    krb5-libs \
    postgresql-client \
    aws-cli \
    git \
    openssh \
    netcat-openbsd \
    unzip \
    curl \
    gnu-libiconv \
    busybox=$BUSYBOX_VERSION \
    ssl_client=$SSL_CLIENT_VERSION

# Set the LD_LIBRARY_PATH to include /usr/lib
ENV LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH

RUN adduser -u 10000 -S runtime --home /runtime
ENV JULIA_DEPOT_PATH=/runtime/.julia

# Add or-julia-registry
RUN julia -e 'using Pkg; Pkg.Registry.add("General")'

ENV JULIA_PROJECT @.

RUN julia deploy/packagecompile.jl "$OPTION" && \
  julia -e 'using Pkg; Pkg.instantiate()' && \
  # Change ownership and clear out test keys (using root user)
  chown -R runtime /runtime/.julia/ && \
  find /usr/local/julia/* -type f -regex '.*\/test\/keys\/.*' -delete && \
  find /runtime/.julia/packages/* -type f -regex '.*\/test\/.*.pem' -delete && \
  find /runtime/.julia/* -type f -regex '.*\/test\/.*.key' -delete && \
  find /runtime/.julia/* -type f -regex '.*\/test\/keys\/.*' -delete && \
  find /runtime/.julia/* -type f -name 'redis.key' -delete && \
  apk del gcc git

USER runtime

EXPOSE 6868

ENTRYPOINT ["julia", "-JLrsDataLoader.so", "-e", "LrsDataLoader.run()"]

Error:

 LibPQ.Connection("host=$(pg_params.host) port=$(pg_params.port) dbname=$(pg_params.dbname) user=$(pg_params.user) password=$(pg_params.password)")

signal (11): Segmentation fault
in expression starting at REPL[11]:1
PQconnectionNeedsPassword at /workspace/srcdir/postgres/meson_build/../src/interfaces/libpq/fe-connect.c:7304
PQconnectionNeedsPassword at /runtime/.julia/packages/LibPQ/i4yBe/src/headers/libpq-fe.jl:418 [inlined]
#Connection#17 at /runtime/.julia/packages/LibPQ/i4yBe/src/connections.jl:303
Connection at /runtime/.julia/packages/LibPQ/i4yBe/src/connections.jl:272
_jl_invoke at /buildworker/worker/package_musl64/build/src/gf.c:2237 [inlined]
jl_apply_generic at /buildworker/worker/package_musl64/build/src/gf.c:2419
jl_apply at /buildworker/worker/package_musl64/build/src/julia.h:1703 [inlined]
do_call at /buildworker/worker/package_musl64/build/src/interpreter.c:115
eval_value at /buildworker/worker/package_musl64/build/src/interpreter.c:204
eval_stmt_value at /buildworker/worker/package_musl64/build/src/interpreter.c:155 [inlined]
eval_body at /buildworker/worker/package_musl64/build/src/interpreter.c:562
jl_interpret_toplevel_thunk at /buildworker/worker/package_musl64/build/src/interpreter.c:670
jl_toplevel_eval_flex at /buildworker/worker/package_musl64/build/src/toplevel.c:877
jl_toplevel_eval_flex at /buildworker/worker/package_musl64/build/src/toplevel.c:825
jl_toplevel_eval_in at /buildworker/worker/package_musl64/build/src/toplevel.c:929
eval at ./boot.jl:360 [inlined]
eval_user_input at /buildworker/worker/package_musl64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:139
repl_backend_loop at /buildworker/worker/package_musl64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:200
start_repl_backend at /buildworker/worker/package_musl64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:185
#run_repl#42 at /buildworker/worker/package_musl64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:317
run_repl at /buildworker/worker/package_musl64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:305
_jl_invoke at /buildworker/worker/package_musl64/build/src/gf.c:2237 [inlined]
jl_apply_generic at /buildworker/worker/package_musl64/build/src/gf.c:2419
#881 at ./client.jl:387
jfptr_YY.881_34516.clone_1 at /usr/local/julia/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_musl64/build/src/gf.c:2237 [inlined]
jl_apply_generic at /buildworker/worker/package_musl64/build/src/gf.c:2419
jl_apply at /buildworker/worker/package_musl64/build/src/julia.h:1703 [inlined]
jl_f__call_latest at /buildworker/worker/package_musl64/build/src/builtins.c:719
#invokelatest#2 at ./essentials.jl:708 [inlined]
invokelatest at ./essentials.jl:706 [inlined]
run_main_repl at ./client.jl:372
exec_options at ./client.jl:302
_start at ./client.jl:485
jfptr__start_37230.clone_1 at /usr/local/julia/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_musl64/build/src/gf.c:2237 [inlined]
jl_apply_generic at /buildworker/worker/package_musl64/build/src/gf.c:2419
jl_apply at /buildworker/worker/package_musl64/build/src/julia.h:1703 [inlined]
true_main at /buildworker/worker/package_musl64/build/src/jlapi.c:560
repl_entrypoint at /buildworker/worker/package_musl64/build/src/jlapi.c:702
main at /usr/local/julia/bin/julia (unknown line)
unknown function (ip: 0x7fa36e5fe709)
unknown function (ip: 0x7fff36908860)
unknown function (ip: 0x73646165726873)
Allocations: 15719756 (Pool: 15713447; Big: 6309); GC: 17
Segmentation fault

It used to work before with Alpine 3.18 and LibPQ 1.17.1, but to fix CVEs, we changed the base image to Alpine 3.20 and also updated the LibPQ version. Now it's throwing this error, and I'm not sure what's happening.

Also do note that pg_params contains all the required fields.

iamed2 commented 3 weeks ago

It used to work before with Alpine 3.18 and LibPQ 1.17.1, but to fix CVEs, we changed the base image to Alpine 3.20 and also updated the LibPQ version. Now it's throwing this error, and I'm not sure what's happening.

Can you try Alpine 3.20 and LibPQ 1.17.1, or are they incompatible?

chamikabm commented 3 weeks ago

@iamed2 , I tried it before. It was failing with version 1.17.1 as well, which is why I upgraded to the latest version.