4

This has happened to me on numerous occasions and I hope I can find an answer here.

Sometimes when working with the Rails console and performing an #update or #destroy action on an object, my console will simply freeze after posting "BEGIN" in the log. I currently have one open, a simple destroy, that has been sat there for ten minutes.

i.e.:

my_object.find(permitted_params[:thing][:id]).destroy

CTRL+C on my mac does not kill it and simply renders:

^C^C^C^C^C^C^C^C^C^C

Then when I finally kill the tab and restart the server I get:

A server is already running. Check /path/to/app/tmp/pids/server.pid.

Then when I clear server.pid and try to restart the server I get:

/Users/nickschwaderer/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/socket.rb:206:in `bind': Address already in use - bind(2) for 127.0.0.1:3000 (Errno::EADDRINUSE)

At that point I run lsof -wni tcp:3000, then kill -9 #whatever_my_pid_was, to finally set everything straight to re run the server.

What in the sam blue heck is happening here?

Nick Schwaderer
  • 1,030
  • 1
  • 8
  • 21
  • `^D` might kill it instead? – MMachinegun Jul 18 '16 at 14:52
  • Maybe post the code from your update and destroy actions? Is something there causing the freeze – Ren Jul 18 '16 at 15:10
  • are you using any sql client while development ? Some clients use transaction for update/delete query. Until you close the client, the transaction is not completed. If you're trying to run update/destroy queries on same table from rails console while running a query from sql client, console freezes. – Girish Jul 18 '16 at 18:02

2 Answers2

0

This happened to me recently, and I admit I'm quite ashamed by the reason when I found out.

Make sure you don't have a code halt somewhere. There was a lone binding.pry that fired for some reason even when I tried to remove my object even from the console.

Hyruu
  • 85
  • 6
  • This wasn't the problem in my case, but upvoting for visibility in case others have this issue. I'm leaving this open in case it happens to me again, but for the record I haven't had a repeat of this since my Rails 5 upgrade. – Nick Schwaderer Oct 25 '16 at 10:57
0

This happened with me, but with User.delete(1234). In the end, I just restarted my machine, restarted the database server and it all worked.

Obromios
  • 15,408
  • 15
  • 72
  • 127