11

I have a rails app on heroku that i am unable to run my latest database changes with. Running heroku run rake db:migrate gives me

Running `rake db:migrate` attached to terminal... up, run.3167
!    Heroku client internal error.
!    Search for help at: https://help.heroku.com
!    Or report a bug at: https://github.com/heroku/heroku/issues/new

Error:       Operation timed out - connect(2) (Errno::ETIMEDOUT)
Backtrace:   /Users/gregg/.heroku/client/lib/heroku/client/rendezvous.rb:40:in `initialize'
             /Users/gregg/.heroku/client/lib/heroku/client/rendezvous.rb:40:in `open'
             /Users/gregg/.heroku/client/lib/heroku/client/rendezvous.rb:40:in `block in start'
             /usr/local/heroku/ruby/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
             /Users/gregg/.heroku/client/lib/heroku/client/rendezvous.rb:31:in `start'
             /Users/gregg/.heroku/client/lib/heroku/command/run.rb:132:in `rendezvous_session'
             /Users/gregg/.heroku/client/lib/heroku/command/run.rb:119:in `run_attached'
             /Users/gregg/.heroku/client/lib/heroku/command/run.rb:24:in `index'
             /Users/gregg/.heroku/client/lib/heroku/command.rb:218:in `run'
             /Users/gregg/.heroku/client/lib/heroku/cli.rb:28:in `start'
             /usr/bin/heroku:24:in `<main>'

Command:     heroku run rake db:migrate
Version:     heroku-toolbelt/3.2.1 (x86_64-darwin10.8.0) ruby/1.9.3

And when i tail the logs i see the following:

2014-01-04T20:27:56.438268+00:00 heroku[run.3167]: Awaiting client
2014-01-04T20:27:56.531495+00:00 heroku[run.3167]: State changed from starting to up
2014-01-04T20:26:58.751010+00:00 heroku[router]: at=info method=GETpath=/assets/SanukWebPro-Light.woff host=stormy-savannah-1911.herokuapp.com fwd="98.210.221.215" dyno=web.1 connect=6ms service=134ms status=200 bytes=38568
2014-01-04T20:27:11.027485+00:00 heroku[router]: at=info method=GET path=/articles/new host=stormy-savannah-1911.herokuapp.com fwd="98.210.221.215" dyno=web.1 connect=3ms service=54ms status=200 bytes=7577
2014-01-04T20:28:26.446139+00:00 heroku[run.3167]: Error R13 (Attach error) -> Failed to attach to process
2014-01-04T20:28:27.994826+00:00 heroku[run.3167]: Process exited with status 128
2014-01-04T20:28:28.005837+00:00 heroku[run.3167]: State changed from up to complete

2 Answers2

20

Try to run it in background:

heroku run:detached rake db:migrate

https://devcenter.heroku.com/articles/one-off-dynos#running-tasks-in-background

Andrey Artemyev
  • 452
  • 4
  • 11
  • Works for me too, but can you please explain why this is required? – BobDoolittle Oct 01 '15 at 01:17
  • Cause error was: `Failed to attach to process` in `Running rake db:migrate attached to terminal`. So solution is to run it destached. No ideas about `2014-01-04T20:28:26.446139+00:00 heroku[run.3167]: Error R13 (Attach error) -> Failed to attach to process` – Andrey Artemyev Oct 07 '15 at 21:20
  • 2
    I wanted to understand why "run:detached" fixes the problem, for future reference. I know it works, but not why it works. – BobDoolittle Oct 08 '15 at 18:50
  • 4
    @BobDoolittle `run:detached` doesn't exactly fix the problem, it just doesn't try to attach and therefore the attaching cannot fail. In general, `heroku run` means that your local console will be attached to the command you're running in a one-off dyno, you will be able to see its output and interact with it (stdin, stdout, stderr) are connected. `heroku run:detached` on the other hand will not connect your local console. You won't be able to interact with it (no stdin) and you'll have to check the logs to see if the command succeeded. – Henrik Heimbuerger Jun 20 '16 at 16:50
  • @hheimbuerger Thanks, but do we know why attaching to the local console fails in the first place when running this command? – BobDoolittle Jun 21 '16 at 18:19
  • @BobDoolittle I don't, or I would have answered your question instead of commenting on this one. Just wanted to answer your follow-up question on how detached is different (because magic certainly has nothing to do with it ;) ). I have the same root issue, but I suspect in my case it's a bug in latest Windows 10 preview build. – Henrik Heimbuerger Jun 21 '16 at 20:57
  • Well, if we can't explain how it works, I guess we can't entirely rule out "magic" after all ;-) – BobDoolittle Jun 22 '16 at 22:09
  • I found that at the same time I was experiencing this problem, I was also timed out for ```heroku run console```. However ```heroku maintenance:on``` did work. I suspect (or am hoping) it is just a temporary problem with the heroic developer interface. – Obromios Aug 16 '16 at 06:35
1

After running

    heroku run:detached rake db:migrate

I was able to run successfully

    heroku run rake db:migrate 
keith_o
  • 13
  • 2
  • 2
    I presume this is because once it completed successfully while being run detached, invoking it the second time (without 'detached') does nothing - the database is already set up. – BobDoolittle Oct 01 '15 at 01:19