Mix release crashing due to elixir_ls_utils, despite it not being in `mix deps.tree`

Hello!

I’m using a Dockerfile generated by Fly.io for an Elixir/Phoenix app. Unfortunately it crashes on boot. There’s no information logged to stderr, but the following is visible in erl_crash.dump:

Slogan: Runtime terminating during boot ({badarg,[{io,put_chars,[standard_error,[<<42,42,32,40,69,88,73,84,32,102,114,111,109,32,35,80,73,68,60,48,46,57,56,46,48,62,41,32,97,110,32,101,120,99,101,112,116,105,111,110,32,119,97,115,32,114,97,105,115,101,100,58,10,32,32,32,32,42,42,32,40,69,114,108,97,110,103,69,114,114,111,114,41,32,69,114,108,97,110,103,32,101,114,114,111,114,58,32,58,116,101,114,109,105,110,97,116,101,100,10,32,32,32,32,32,32,32,32,40,101,108,105,120,105,114,32,49,46,49,54,46,48,41,32,108,105,98,47,105,111,46,101,120,58,50,55,52,58,32,73,79,46,98,105,110,119,114,105,116,101,47,50,10,32,32,32,32,32,32,32,32,40,101,108,105,120,105,114,95,108,115,95,117,116,105,108,115,32,48,46,50,48,46,48,41,32,108,105,98,47,111,117,116,112,117,116,95,100,101,118,105,99,101,46,101,120,58,51,55,58,32,69,108,105,120,105,114,76,83,46,85,116,105,108,115,46,79,117,116,112,117,116,68,101,118,105,99,101,46,108,111,111,112,47,49,10,32,32,32,32,32,32,32,32,40,101,108,105,120,105,114,32,49,46,49,54,46,48,41,32,108,105,98,47,116

I’m not sure what’s going on there, but plugging the binary into iex I see:

** (EXIT from #PID<0.98.0>) an exception was raised:
    ** (ErlangError) Erlang error: :terminated
        (elixir 1.16.0) lib/io.ex:274: IO.binwrite/2
        (elixir_ls_utils 0.20.0) lib/output_device.ex:37: ElixirLS.Utils.OutputDevice.loop/1
        (elixir 1.16.0) lib/t"

Now I’m quite confused because

  1. My Dockerfile is using hexpm/elixir:1.16.3-erlang-26.2.5-debian-bullseye-20240513-slim, so where is elixir 1.16.0 coming from?
  2. Where is elixir_ls_utils 0.20.0 coming from? It’s not a direct dependency in mix.exs, a transitive dependency in mix deps.tree, or mentioned in the Dockerfile.

Here’s the Dockerfile that fly launch generated:

ARG ELIXIR_VERSION=1.16.3
ARG OTP_VERSION=26.2.5
ARG DEBIAN_VERSION=bullseye-20240513-slim

ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"

FROM ${BUILDER_IMAGE} as builder

# install build dependencies
RUN apt-get update -y \
    && apt-get install -y build-essential git libexpat1-dev \
    && apt-get clean && rm -f /var/lib/apt/lists/*_*

# prepare build dir
WORKDIR /app

# install hex + rebar
RUN mix local.hex --force && \
    mix local.rebar --force

# set build ENV
ENV MIX_ENV="prod"

# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config

# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile

COPY priv priv

COPY lib lib

COPY assets assets

# compile assets
RUN mix assets.deploy

# Compile the release
RUN mix compile

# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/

COPY rel rel
RUN mix release

# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}

RUN apt-get update -y && \
  apt-get install -y libstdc++6 openssl libexpat1 libncurses5 locales ca-certificates \
  && apt-get clean && rm -f /var/lib/apt/lists/*_*

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

WORKDIR "/app"
RUN chown nobody /app

# set runner ENV
ENV MIX_ENV="prod"

# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/foo ./

USER nobody
CMD ["/app/bin/server"]

Does anyone know what I could do to debug this?

I still have no idea why elixir 1.16.0 and elixir_ls are in the stacktrace, but after modifying the Dockerfile to use Debian 12 (bookworm) instead of Debian 11 (bullseye), I now hit a different error! Very mysterious.

1 Like