Crash dump when installing Phoenix on Mac M2: eheap_alloc: Cannot allocate X bytes of memory (of type "heap_frag")

Hi all,

Before this, I have no issues install Elixir and Erlang using ASDF on my MacBook M2 (64GB RAM).

But today I chose to update it, all seemed fine until I tried to install phoenix framework.

I have uninstalled all and installed back having the same issue. Not sure what’s the issue?

mix archive.install hex phx_new
Resolving Hex dependencies...
eheap_alloc: Cannot allocate 976733209832459912 bytes of memory (of type "heap_frag").

Crash dump is being written to: erl_crash.dump...beam/erl_term.h:1492:tag_val_def() Assertion failed: tag_val_def error
[1]    25425 abort      mix archive.install hex phx_new

Any help? Thanks.

1 Like

I have the same problem doing mix deps.get after installing the latest Erlang 26.2.3. Try installing 26.2.2 and I guess it would work. I’m on a MacBook Pro M1 (32 GB).

I don’t know enough to tell what’s the underlying cause.

1 Like

I tried that version too, can’t work either.

It seems erlang 26.2.1 works for M2. Not 26.2.2 or latest 26.2.3.

Though it’s weird as based on above, @champeric can get 26.2.2 working on M1 ?

and it seems I can’t simply update to latest Erlang too.

That’s weird. I’m also using ASDF for managing both Elixir and Erlang and no problem with Elixir 1.16.1-otp-26 with Erlang 26.2.2.

Actually I can install 26.2.2 or 26.2.3, just when I run this

mix archive.install hex phx_new

will hit the error.

Running iex won’t see the issue.

I just ran into the same issue on a MacBook M2 Pro 16Gb with 26.2.3, no issues with 26.2.2, I use mise (successor of rtx) for my version management.

1 Like

I opened an issue on the Erlang github page. mix deps.get crashes on 26.2.3 - M2 Mac · Issue #8238 · erlang/otp · GitHub

4 Likes

A workaround is compiling Hex from scratch on that OTP version. It can be easily done using this command:

mix archive.install github hexpm/hex branch latest
27 Likes

Thanks @wojtekmach

God (or your preferred diety), I love this community.

4 Likes

Thanks, this works. Anyway this is what I do, so future others can refer too.

// check installed versions
asdf current erlang
asdf current elixir

asdf uninstall erlang 26.2.1 // assume this is global version
asdf uninstall elixir 1.16.1-otp-26 // uninstall, assume this is global version

// install
asdf install erlang latest    // assume latest is 26.2.3
asdf global erlang latest
asdf current erlang
asdf list-all elixir      // assume is 1.16.1-otp-26
asdf install elixir 1.16.1-otp-26
asdf global elixir 1.16.1-otp-26
asdf reshim elixir
iex // testing
elixir -v // testing
mix archive.install github hexpm/hex branch latest
mix archive.install hex phx_new
mix phx.new hello // create phoenix project to ensure no errors
4 Likes

Well this is weird. I’m running into this same problem on my Mac M2… but I’m not using asdf. I’m using docker/docker-compose.

This is my Dockerfile:

FROM elixir:1.15.7

ARG NODE_VERSION=20.10.0

RUN apt update \
  && apt upgrade -y \
  && apt install -y bash curl git build-essential inotify-tools npm

ADD . /docker/app

WORKDIR /docker/app

RUN mix local.hex --force \
  && mix local.rebar --force \
  && mix deps.get \
  && mix deps.compile

ARG DEFAULT_PORT 4500

EXPOSE ${DEFAULT_PORT}

CMD ["mix", "phx.server"]

I’m new to Elixir so this is a bit of a bummer. Any ideas what I’m doing wrong?

The bug is not asdf specific. It affects all aarch64 systems running this specific otp patch release.

I‘d suggest using hexpm/elixir images, which let you control the otp version used. Then you can use the last patch release until the fix for the bug is out.

5 Likes

It seems the fix is merged but new docker images haven’t been released.

Dang, this just saved my bacon. THANK YOU!

1 Like

Thank you so much!

I can’t seem to find a working solution to get my Dockerfile which needs to run on ARM64 to work.

My dockerfile looks like this:

# Use an official Elixir runtime as a parent image
FROM elixir:latest

ENV ERL_FLAGS="+JPperf true"
# Set the working directory in the container
WORKDIR /app

# Fix bug https://github.com/erlang/otp/issues/8238
RUN mix archive.install github hexpm/hex branch latest

# Install hex package manager
RUN mix local.hex --force

# Install the latest Phoenix
RUN mix archive.install hex phx_new  --force

# Install rebar
RUN mix local.rebar --force

# Copy the app contents into the container at /app
COPY ./ /app

# Install dependencies
RUN mix deps.get

# Compile the project
RUN mix do compile

CMD ["/app/entrypoint.sh"]

I tried the solution @wojtekmach provided with the mix archive.install github hexpm/hex branch latest, but the build process still ends up breaking on:

RUN mix archive.install hex phx_new --force

with:
eheap_alloc: Cannot allocate 976733209832459912 bytes of memory (of type "heap_frag")

I am new to Elixir/Phoenix, so properly resolving this bug is definitely out of my scope of knowledge.

1 Like

Try removing this line from your Dockerfile:

RUN mix local.hex --force