gis-ops / docker-valhalla

This is our flexible Docker repository for the Valhalla routing engine
MIT License
228 stars 69 forks source link

Segmentation Fault when running the image on M1 Mac #102

Closed devdattaT closed 1 year ago

devdattaT commented 1 year ago

I'm trying to run the docker image on my M1 Mac Pro.

If I directly run the docker image, I get the warning: WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested

Building the container on my local with --platform linux/amd64 works, but when I run it with same platform, I get a Segmentation Fault.

I ran it with the following command: docker run -t --name valhalla_gis-ops -p 8002:8002 -v $PWD/custom_files:/custom_files --platform linux/amd64 ghcr.io/gis-ops/docker-valhalla/valhalla:latest

I have placed an extract for a Metropolitan area in the custom_files directory.

It fails with the following messages:

INFO: Running container with user valhalla UID 59999 and GID 59999.

WARNING: Hash not found for: /custom_files/pune.osm.pbf! WARNING: No routing tiles found at /custom_files/valhalla_tiles.tar or /custom_files/valhalla_tiles, starting new build.. INFO: Running build tiles with: /custom_files/valhalla.json /custom_files/pune.osm.pbf

============================ = Build the initial graph. =

2023/04/17 07:12:19.98408 [INFO] Start stage = initialize End stage = build qemu: uncaught target signal 11 (Segmentation fault) - core dumped /valhalla/scripts/configure_valhalla.sh: line 172: 114 Segmentation fault valhalla_build_tiles -c ${CONFIG_FILE} -e build ${files}

nilsnolde commented 1 year ago

Apple Silicon needs to be first added to the Valhalla base image (see Dockerfile), only then to our image. Otherwise it'll always pull the x64 Valhalla base image, then apply a arm64 overlay for this image, which won't work.

There's nothing we can do about it and honestly I wouldn't want to host arm64 images either here or for upstream Valhalla as long as there's no arm64 CI runners (didn't check though). Cross-compiling takes ages and Linux arm64 is still not mainstream enough (and hardly anyone cares about Apple Silicon haha kidding).

mikeyhew commented 1 year ago

I don't think an arm64 image is required for this to work on M1, from what I can tell it's trying to run the amd64 image under emulation with qemu, which should work in theory but somehow the container is failing with a segmentation fault. I guess debugging it still requires having access to an M1 mac, though.

I'm here because I'm getting the same message about a segmentation fault when I run the container in docker-compose on my M1 Macbook Air. Here's a sequence of steps that should reproduce it:

# install and setup docker with colima
brew install colima docker docker-compose
colima start

# set up a directory to reproduce this in
mkdir valhalla-segementation-fault-repro
cd valhalla-segmentation-fault-repro

# dowload map files for andorra (from the Readme)
mkdir custom_files
wget -O custom_files/andorra-latest.osm.pbf https://download.geofabrik.de/europe/andorra-latest.osm.pbf

# copy the docker-compose template from master
wget -O docker-compose.yml https://raw.githubusercontent.com/gis-ops/docker-valhalla/master/docker-compose.yml.template

docker-compose up

the docker-compose up command outputs this for me:

[+] Building 0.0s (0/0)
[+] Running 2/0
 ✔ Container valhalla_latest                                                                                                                               Recreated0.0s
 ! valhalla The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested 0.0s
Attaching to valhalla_latest
valhalla_latest  |
valhalla_latest  | INFO: Running container with user valhalla UID 59999 and GID 59999.
valhalla_latest  |
valhalla_latest  | find: '/custom_files/transit_tiles': No such file or directory
valhalla_latest  | WARNING: Hash not found for: /custom_files/andorra-latest.osm.pbf!
valhalla_latest  | WARNING: No routing tiles found at /custom_files/valhalla_tiles.tar or /custom_files/valhalla_tiles, starting a new build
valhalla_latest  | INFO: Running build tiles with: /custom_files/valhalla.json /custom_files/andorra-latest.osm.pbf
valhalla_latest  |
valhalla_latest  | ============================
valhalla_latest  | = Build the initial graph. =
valhalla_latest  | ============================
valhalla_latest  | 2023/06/12 03:45:59.858157 [INFO] Start stage = initialize End stage = build
valhalla_latest  | qemu: uncaught target signal 11 (Segmentation fault) - core dumped
valhalla_latest  | /valhalla/scripts/configure_valhalla.sh: line 210:   143 Segmentation fault      valhalla_build_tiles -c ${CONFIG_FILE} -e build ${files}
valhalla_latest exited with code 1

I'm a little out of practice with C++ and debugging segmentation faults. Any idea how I can get more information on where and why the segfault is happening?

I've tried getting a core dump. From everything I've read there should be a core file in the working directory on the container after the process fails, but it's not showing up. Here are the steps I've tried:

docker-compose run --entrypoint "bash" valhalla

# The rest of these commands are from within the container

# enable core dumps if they aren't already enabled
ulimit -c unlimited

# run the actual command that the container normally runs
/valhalla/scripts/run.sh build_tiles

# from what I've gathered, there should now be a file in the current directory called `core` containing a core dump, but I don't see one
Asher-JH commented 11 months ago

Currently facing the same issue as you guys @devdattaT @mikeyhew . Built using the --platform flag & running on a M2 Mac

ImreSamu commented 11 months ago

info: Upstream ( valhalla) Arm support - work in progress :

nilsnolde commented 11 months ago

Did you try first building Valhalla base locally and then reference it in this Dockerfile? I got forced onto M1 so I routinely build natively. There’s a PR waiting to fix a protobuf issue you might run into: https://github.com/valhalla/valhalla/pull/4207.