This app demos a problem I'm currently having when running code using the or-tools
gem in a web server on my local machine (a MacBook Air with an M1). The problem I'm having is that it errors out with stack level too deep
when it runs the solver.solve
gem code. The stack trace only contains information about what code called this code, not anything about what happens inside solver.solve
.
$ ruby run_in_web_server.rb
... server starts ...
... I visit localhost:4567 ...
2022-02-07 12:26:26 - SystemStackError - stack level too deep:
/Users/jonathan.mohrbacher/Code/stack-overflow/lib/demo/solver.rb:142:in `solve'
/Users/jonathan.mohrbacher/Code/stack-overflow/lib/demo/solver.rb:142:in `run_solver'
/Users/jonathan.mohrbacher/Code/stack-overflow/lib/demo/solver.rb:43:in `solve'
/Users/jonathan.mohrbacher/Code/stack-overflow/lib/demo/solver.rb:23:in `solve'
/Users/jonathan.mohrbacher/Code/stack-overflow/lib/demo.rb:18:in `run'
run_in_web_server.rb:10:in `block in <main>'
... sinatra-specific stack trace ...
However, when I run this code in the terminal, I don't have this problem. And when I run this code in docker, I don't have this problem. So my hunch is that on Macs with M1 chips, there's something wrong with either the or-tools
gem or the underlying or-tools
binary.
To install this app locally on a mac, you first need Homebrew and rbenv
setup on your machine.
- Install ruby 3.1.0 (you may already have it installed).
rbenv install -s $(cat .ruby-version) gem update --system gem install bundler rbenv rehash
- Install
or-tools
.brew install or-tools
- Tell
bundle
where to find your installation ofor-tools
.bundle config build.or-tools --with-or-tools-dir=/opt/homebrew
- Install the gems.
bundle
- Run the app one time in the terminal and exit.
ruby run_in_terminal.rb
- Run the web server.
ruby run_in_web_server.rb
- View it at http://localhost:4567
- On my machine, this is where I hit the
stack level too deep
error!
- Build the image.
docker-compose build
- Run the app one time in the terminal and exit.
docker-compose run --rm app ruby run_in_terminal.rb
- Run the web server.
docker-compose run --rm --service-ports app ruby run_in_web_server.rb
- View it at http://localhost:4567
- Drop into the container.
docker-compose run --rm --service-ports app bash